设置GitSource Control
You can use Git™ source control in MATLAB®管理您的文件并与他人合作。使用git,您可以跟踪文件的更改并稍后再召回特定版本。有关更多信息,请参阅克隆git存储库andAdd a Project to Source Control。
Before using Git, follow these steps to set it up for MATLAB:
Register your binary files with Git to avoid file corruption. (Required for all systems)
Configure MATLAB for Git on a Windows®系统。(为Windows系统推荐)
Configure MATLAB to use Git SSH authentication or install a Git credential helper to prevent frequent login prompts. (Optional)
Disable compression for Simulink®models to reduce your Git repository size. (Optional)
如果您正在使用大文件,则配置Git以使用Git LFS。(可选的)
Configure Git to use MATLAB for Diff and Merge. (Optional)
Before R2020b, a command-line Git client must be installed to use Git to merge branches in MATLAB. For more information, see安装Command-Line Git Client。
注册二进制文件Git
If you use third-party source control tools, you must register your MATLAB and Simulink file extensions such as。mlx
,,,,。垫
,,,,。fig
,,,,.mlapp
,,,,。mdl
,,,,.slx
,,,,.mdlp
,,,,.slxp
,,,,。sldd
,,,,and.p
as binary formats. Also register extensions for MEX files, such as。mexa64
,,,,。mexmaci64
,,,,and.mexw64
。If you do not register the extensions, these tools can corrupt your files when you submit them by changing end-of-line characters, expanding tokens, substituting keywords, or attempting to automerge. Corruption can occur if you use the source control tools outside of MATLAB or if you try submitting files from MATLAB without first registering your file formats.
Also check that other file extensions are registered as binary to avoid corruption at check-in. Check and register file extensions such as。xlsx
,,,,。jpg
,,,,.pdf
,,,,。docx
,,,,and so on.
To register your binary file extensions with Git, add them to a。gitattributes
file. If you create a new project that uses Git source control or switch an existing project from another source control system to Git source control, MATLAB automatically creates a。gitattributes
文件并用要注册的常见二进制文件列表填充它。
如果一个。gitattributes
文件不是自动创建的,您可以创建一个包含要注册的常见二进制文件列表。在MATLAB命令窗口中,输入:
copyfile(fullfile(matlabroot,,'toolbox',,,,'shared',,,,'cmlink',,,,“git”,,,,'auxiliary_files',,,,...'mwgitattributes'),fullfile(PWD,'.gitattributes'))
Alternatively, to create a blank。gitattributes
file, enter:
编辑。gitattributes
To register binary files that are not already included in the。gitattributes
文件,为您需要的每个文件类型添加一行。例如,*.mlapp二进制
。
ConfigureMATLABforGitonWindows
On Windows systems, if you are working with files that have long paths, enable support for long paths. In addition, to use Git hooks with MATLAB, install Cygwin and add it to the MATLAB library path. Git hooks are custom scripts that can be triggered by operations such as committing, merging, and receiving pushed commits.
启用对长路径的金宝app支持(建议)
为了支持Window金宝apps系统上的长路径,请在MATLAB中运行此命令:
!git config -Global Core.LongPath true true
安装Cygwin(可选)
To install Cygwin on a Windows system and add it to the MATLAB library path:
Download and run the installer fromhttps://www.cygwin.com/。
In MATLAB, open
librarypath.txt
。编辑(fullfile(matlabroot,"toolbox",,,,"local",,,,"librarypath.txt"))
Add the Cygwin bin folder location to the end of
librarypath.txt
,,,,for example,C:\cygwin64\bin
。## ## file:librarypath.txt ## ##条目:## o path_to_jnifile ## o [alpha,glnx86,sol2,unix,win32,mac] = path_to_to_jnifile ## o $ matlabroot/path_to_to_to_to_to_to_jnifile ##path_to_jnifile ## $ matlabroot/bin/$ ach
如果您没有权限编辑
librarypath.txt
file, seeLocate Native Method Libraries。Restart MATLAB.
ConfigureMATLAB使用GitSSH Authentication
为了防止使用HTTPS与远程存储库进行交互时频繁的登录提示,请添加新的公钥并使用SSH克隆存储库。该表提供了有关如何配置MATLAB以使用操作系统使用SSH身份验证的说明。
Operating System | Instructions |
---|---|
Windows |
|
Linux®andmacOS |
|
安装Git凭证助手
要配置MATLAB以记住使用GIT时的用户名和密码,请安装凭证助手。所有平台的推荐凭证助理是GIT凭据管理器Core。
例如,to install Git Credential Manager Core on a Windows system, download and run the Git for Windows installer using the instructions described in安装Command-Line Git Client。在里面Choose a credential helper安装程序的部分,选择Git Credential Manager Coreas the credential helper.
禁用压缩金宝appModels
You can reduce your Git repository size by saving Simulink models without compression. Turning off compression results in larger SLX files on disk but reduces repository size.
要与新的SLX文件一起使用此设置,请使用具有SLX压缩设置为无的模型模板创建模型。对于现有的SLX文件,设置压缩,然后保存模型。有关更多信息,请参阅设置SLX压缩水平。
ConfigureGit使用GitLFS
If you are working with large files, configure Git to use Git Large File Storage (LFS) by installing command-line Git and setting up LFS.
例如,要使用Windows系统上使用Git LFS,请使用中描述的说明下载Windows安装程序的Git安装Command-Line Git Client。在里面选择组件section of the Git for Windows installer, select thegit LFS(大文件支持)金宝appandAssociate .sh files to be run with Bash选项。
MATLAB不支持Git LFS金宝app锁定。此外,MATLAB不支持LFS命令,例如金宝appgit lfs track
。Use!gitlfs track
反而。
笔记
Git LFS uses Git hooks. Make sure that you have Cygwin installed. For more information, seeConfigure MATLAB for Git on Windows。
ConfigureGit使用MATLABfor Diff and Merge
You can configure Git to use the MATLAB Comparison Tool for diff and merge. The MATLAB Comparison Tool provides tools for merging MathWorks®files such as live scripts, MAT, SLX, or MDL files. You can use the automerge tool with Git to automatically merge branches that contain changes in different subsystems in the same SLX file.
For more information about how to configure Git to use the MATLAB Comparison Tool, seeCustomize External Source Control to Use MATLAB for Diff and Merge。
安装Command-Line Git Client
To use Git LFS or a credential helper, you must install a command-line Git client and make it available system-wide. Before R2020b, a command-line Git client must be installed to use Git to merge branches in MATLAB.
要检查是否安装了git,请输入命令!git
在MATLAB命令窗口中。如果命令不返回任何内容,则需要安装命令行Git。This table provides instructions on how to install command-line Git based on your operating system.
Operating System | Instructions |
---|---|
Windows |
|
Linux | Git is available for most distributions. Install Git for your distribution. For example, on Debian®,,,,install Git by entering: sudo apt-get安装git |
macOS | On Mavericks (10.9) or above, run Git from a Terminal window. If you do not have Git installed already, it will prompt you to install Xcode Command Line Tools. For more information, seehttps://git-scm.com/doc。 |