Using a Project with Git
This example shows how to use a project to manage the files within your design. Starting with an existing project that is already checked into source control, this example shows how to view modified files, compare file revisions, and analyze project dependencies.
Set up the Example Files and Open the Project
Create and open a working copy of the project example files. MATLAB® copies the files to an example folder so that you can edit them. The example project is under Git™ source control.
Building with 'MinGW64 Compiler (C)'. MEX completed successfully.
ans = Project with properties: Name: "Airframe Example" SourceControlIntegration: "Git" RepositoryLocation: "C:\workSpace\examples\repositories\airframe" SourceControlMessages: ["Current branch: master" "No remote tracking branch" "Branch status: Normal"] ReadOnly: 0 TopLevel: 1 Dependencies: [1×1 digraph] Categories: [1×1 matlab.project.Category] Files: [1×32 matlab.project.ProjectFile] Shortcuts: [1×7 matlab.project.Shortcut] ProjectPath: [1×7 matlab.project.PathFolder] ProjectReferences: [1×0 matlab.project.ProjectReference] StartupFiles: [1×0 string] ShutdownFiles: [1×0 string] DefinitionFilesType: FixedPathMultiFile Description: "This is an example project.↵↵Use the "Project Shortcuts" toolstrip tab to find ways of getting started with this project." RootFolder: "C:\workSpace\examples\airframe" SimulinkCodeGenFolder: "C:\workSpace\examples\airframe\work\codegen" ProjectStartupFolder: "C:\workSpace\examples\airframe" SimulinkCacheFolder: "C:\workSpace\examples\airframe\work\cache"
Manage the Project Path
When you open your project, MATLAB adds the project path to the MATLAB search path before applying startup shortcuts.
When you close your project, MATLAB removes the project path from the MATLAB search path after applying shutdown shortcuts.
1. To add or remove folders to the project path, on the Project tab, in the Environment section, click Project Path:
To add a folder (without subfolders) to the project path, click Add Folder. If you want to add a folder and its subfolders, click Add with Subfolders instead. Then use the Open dialog box to add the new folder.
To remove a folder from the project path, from the display list, select the folder. Then click Remove.
It is important to add project files to the project path to ensure the Dependency Analyzer detects all project files.
Specify Project Details, Startup Folder, and Derived Files Folders
2. On the Project tab, in the Environment section, click Details. Use the Project Details dialog box to:
Edit the project name or add a description.
View the Project root folder. You can change your project root by moving your entire project on your file system, and reopening your project in its new location. All project file paths are stored as relative paths.
View or edit the Start Up folder. By default, this is set to the project root. When you open the project, the current working folder changes to the project root folder. You can specify a different startup folder or click Clear.
View or edit the Simulation cache folder and Code generation folder.
To change the default project root for new projects, on the MATLAB Home tab, in the Environment section, click Preferences. Select MATLAB > Project and specify the Default folder.
Automate Startup and Shutdown Tasks
You can set project files, such as MATLAB scripts and Simulink® models, to run, open, or close when the project opens or closes.
3. To configure an existing file to run on project startup and shutdown, or to specify environment options, click the Startup Shutdown button in the Project tab. In the Manage Project Startup and Shutdown dialog box
Add or remove startup and shutdown files. If execution order is important, change the order using the arrow buttons.
Use the check boxes to specify environment options. Select Start Simulink before this project starts to start Simulink when you open the project. Select Refresh Simulink customizations to run
sl_customizationfiles on project startup and shutdown.
Project Shortcuts for Common Tasks
Create project shortcuts for common tasks to make it easy to find and access important files and operations. For example, find and open top models, run code, and simulate models.
4. On the Project Shortcuts tab, this example project has shortcuts for the top-level model, a utility function to rebuild s-functions, and a design description document.
Click the shortcut
F14 Modelto open the root model for this project.
Click the shortcut Rebuild Project's S-functions to generate the S-Function.
Click the New Shortcut button to create new shortcuts for a project file.
Right-click a shortcut and select Edit Shortcut to edit a shortcut.
View Source Control Information
On the Project tab, in the Source Control section, click Git Details.
5. Use the Source Control Information dialog box to:
View the Repository location folder. You can change your project root by moving your entire project on your file system, and reopening your project in its new location. All project file paths are stored as relative paths.
View or change the used source control integration.
Explore Files Views
6. In the Files view, select the Project (number of files) view to manage the files within your project. This view only shows files that are part of your project.
7. Use the All view to see all the files in your working copy. This shows all the files that are under the project root, not just the files that are in the project. This view is useful for adding files to your project from your working copy.
8. Use the Modified (number of files) view to review the modified files before committing your changes to source control. The modified files view is visible only if you are using source control with your project.
9. In any Files view, at the top right, change the layout from Tree to List to view the files as a list. Click the Organize View button to customize the views and to sort files.
The Git column provides source control information on individual files such as Unmodified, Added, Modified, or Deleted.
View Modified Files and Compare Revisions
10. Open and make a change to one of the models in the
models folder or to one of the MATLAB files in the
utility folder. For example, add a comment in
find_top_models.m in the
11. To review, analyze, and commit modified or added project files, use the Modified (number of files) view. You see:
The file you made changes to, for example,
The files stored in the resources/project folder. These are internal project definition files generated by your changes. The project definition files allow you to add metadata to files, for example, by creating shortcuts, adding labels, and adding a project description. Project definition files also define the files that are added to your project. You can review changes in revisions of project definition files like any other project files.
12. To review changes in a modified file, right-click selected file, for example,
Select Compare > Compare to Ancestor to run a comparison against the local Git repository.
Select Compare > Compare to Revision to compare the file to other revisions.
13. The Comparison Tool summarizes results in a report. Purple indicates modified items, blue indicates inserted items, and yellow indicates deleted items. To save a printable version of the report, select Publish > HTML, Word, or PDF.
14. If you are happy with your changes, on the Project tab, click the Commit button to commit your changes to source control.
Analyze Project Dependencies
15. Use the Dependency Analyzer to investigate dependencies visually and explore the structure of your project. On the Project tab, click the down arrow to expand the Tools gallery. Under Apps, click Dependency Analyzer.
The Dependency Analyzer summarizes the results in the pane on the right. It lists the names of the used Products and Add-Ons. It detects problems, such as missing files, files not in the project, unsaved changes, and out-of-date derived files. In this example, the analyzer identifies a "File not in project" and tags it with a warning sign .
16. To highlight problem files, in the Problems section, point to the problem message and click the magnifying glass. In this example, the
timesthree.mexw64 file is required by the project but is not currently part of it. Right-click
timesthree.mexw64 and select Add to Project or Hide Warnings. The next time you run the dependency analysis, the analyzer will not mark this file as a problem.
17. Perform an impact analysis on a selected file.
An impact analysis shows you how a change affects other files before you make the change. For example, to find required files for
timesthree.mexw64 to run properly, right-click
timesthree.mexw64 and select Find Required. To find how changes to
timesthree.mexw64 impact files
timesthree.mexw64 and select Find Impacted.