Main Content

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.

sldemo_slproject_airframe
Building with 'MinGW64 Compiler (C)'. MEX completed successfully.
ans =项目属性:名称:“机体穰mple" 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 theProjecttab, in theEnvironmentsection, clickProject Path:

  • To add a folder (without subfolders) to the project path, clickAdd Folder. If you want to add a folder and its subfolders, clickAdd with Subfoldersinstead. 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 clickRemove.

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 theProjecttab, in theEnvironmentsection, clickDetails. Use the Project Details dialog box to:

  • Edit the project name or add a description.

  • View theProject rootfolder. 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 theStart Upfolder. 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 clickClear.

  • View or edit theSimulation cache folderandCode generation folder.

To change the default project root for new projects, on the MATLABHometab, in theEnvironmentsection, clickPreferences.SelectMATLAB > Projectand specify theDefault 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 theStartup Shutdownbutton in theProjecttab. 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. SelectStart Simulink before this project startsto start Simulink when you open the project. SelectRefresh Simulink customizationsto runsl_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 theProject Shortcutstab, this example project has shortcuts for the top-level model, a utility function to rebuild s-functions, and a design description document.

  • Click the shortcutF14模型to open the root model for this project.

  • Click the shortcutRebuild Project's S-functionsto generate the S-Function.

  • Click theNew Shortcutbutton to create new shortcuts for a project file.

  • Right-click a shortcut and selectEdit Shortcutto edit a shortcut.

View Source Control Information

On theProjecttab, in theSource Controlsection, clickGitDetails.

5.Use the Source Control Information dialog box to:

  • View theRepository locationfolder. 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 theFilesview, select theProject (number of files)view to manage the files within your project. This view only shows files that are part of your project.

7. Use theAllview 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 theModified (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 anyFilesview, at the top right, change the layout fromTreetoListto view the files as a list. Click the Organize View buttonto customize the views and to sort files.

TheGitcolumn 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 themodelsfolder or to one of the MATLAB files in theutilityfolder. For example, add a comment infind_top_models.min theutilityfolder.

11. To review, analyze, and commit modified or added project files, use theModified (number of files)view. You see:

  • The file you made changes to, for example,find_top_models.m.

  • 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,find_top_models.m

  • SelectCompare>Compare to Ancestorto run a comparison against the local Git repository.

  • SelectCompare>Compare to Revisionto 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, selectPublish> HTML,Word, orPDF.

14. If you are happy with your changes, on theProjecttab, click theCommitbutton to commit your changes to source control.

Analyze Project Dependencies

15.使用分析仪调查dep的依赖endencies visually and explore the structure of your project. On theProjecttab, click the down arrow to expand theToolsgallery. UnderApps, clickDependency Analyzer.

The Dependency Analyzer summarizes the results in the pane on the right. It lists the names of the used下载188bet金宝搏andAdd-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 theProblemssection, point to the problem message and click the magnifying glass. In this example, thetimesthree.mexw64 fileis required by the project but is not currently part of it. Right-clicktimesthree.mexw64and selectAdd to ProjectorHide 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 fortimesthree.mexw64to run properly, right-clicktimesthree.mexw64and selectFind Required. To find how changes totimesthree.mexw64impact files,right-clicktimesthree.mexw64and selectFind Impacted.

See Also

Resolve Conflicts with Simulink Three-Way Merge

Perform Impact Analysis with a Project

Run Custom Tasks with a Project

Further Information

Project Management