Set Up SVN Source Control
You can use Subversion® (SVN) source control in MATLAB® to manage your files and collaborate with others. For more information, see Work with Files Under SVN in MATLAB.
Before using SVN, follow these steps to set it up for MATLAB:
(Recommended) Use the standard SVN repository structure.
(Required for all systems) Register your binary files with SVN to avoid file corruption.
(Optional) Enforce locking files before editing.
Use Standard SVN Repository Structure
Create your repository with the standard tags,
trunk, and branches folders, and check out
files from trunk. The Subversion project recommends using this repository structure. For more
information, see https://svn.apache.org/repos/asf/subversion/trunk/doc/user/svn-best-practices.html.
Register Binary Files with SVN
If you use third-party source control tools, you must register your MATLAB and Simulink® file extensions such as .mlx, .mat,
.fig, .mlapp, .mdl,
.slx, .mdlp, .slxp,
.sldd, and .p as binary formats. Also register
extensions for MEX files, such as .mexa64, .mexmaci64,
.mexmaca64, 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 register other file extensions, such as .xlsx,
.jpg, .pdf, and .docx, as binary
formats to avoid corruption during the check-in operation.
You must register binary files if you use any version of SVN, including the built-in SVN integration provided by MATLAB. If you do not register your extensions as binary, SVN might add annotations to conflicted MATLAB files and attempt automerge. To avoid this problem when using SVN, register file extensions.
Locate your SVN
configfile. Look for the file in these locations:On Windows® –
C:\Users\ormyusername\AppData\Roaming\Subversion\configC:\Documents and Settings\myusername\Application Data\Subversion\configOn Linux® or macOS –
~/.subversion
If you do not find an SVN
configfile, create a new one by following the steps in the Create SVN Config File section.If you find an existing SVN
configfile, you have previously installed SVN. Edit theconfigfile by following the steps in the Update Existing SVN Config File section.
Create SVN Config File
If you do not find an SVN
configfile, create a text file containing these lines:[miscellany] enable-auto-props = yes [auto-props] *.mlx = svn:mime-type=application/octet-stream *.mat = svn:mime-type=application/octet-stream *.fig = svn:mime-type=application/octet-stream *.mdl = svn:mime-type=application/octet-stream *.slx = svn:mime-type=application/octet-stream *.mlapp = svn:mime-type=application/octet-stream *.p = svn:mime-type=application/octet-stream *.mdlp = svn:mime-type=application/octet-stream *.slxp = svn:mime-type=application/octet-stream *.sldd = svn:mime-type=application/octet-stream *.slxc = svn:mime-type=application/octet-stream *.mlproj = svn:mime-type=application/octet-stream *.mldatx = svn:mime-type=application/octet-stream *.slreqx = svn:mime-type=application/octet-stream *.sfx = svn:mime-type=application/octet-stream *.sltx = svn:mime-type=application/octet-stream
Check for other file types you use that you also need to register as binary to avoid corruption at check-in. Check for files such as MEX-files (
.mexa64,.mexmaci64,.mexw64),.xlsx,.jpg,.pdf,.docx, etc. Add a line to theconfigfile for each file type you need. Examples:*.mexa64 = svn:mime-type=application/octet-stream *.mexw64 = svn:mime-type=application/octet-stream *.mexmaci64 = svn:mime-type=application/octet-stream *.xlsx = svn:mime-type=application/octet-stream *.docx = svn:mime-type=application/octet-stream *.pdf = svn:mime-type=application/octet-stream *.jpg = svn:mime-type=application/octet-stream *.png = svn:mime-type=application/octet-stream
Name the file
configand save it in the appropriate location.On Windows –
C:\Users\ormyusername\AppData\Roaming\Subversion\configC:\Documents and Settings\myusername\Application Data\Subversion\configOn Linux or macOS –
~/.subversion
After you create the SVN config file, SVN treats new files
with these extensions as binary. If you already have binary files in
repositories, see Register Files Already in Repositories.
Update Existing SVN Config File
If you find an existing SVNconfig file, you have previously
installed SVN. Edit the config file to register files as
binary.
Edit the SVN
configfile in a text editor.Locate the
[miscellany]section, and verify that this line enablesauto-propswithyes.Ensure that this line does not begin with aenable-auto-props = yes
#character, which indicates that the line is commented. If the line begins with a#character, delete the character.Locate the
[auto-props]section. Ensure that the[auto-props]section does not begin with a#character. If the section begins with a#character, delete the character.Add these lines at the end of the
[auto-props]section:These lines prevent SVN from adding annotations to conflicted MATLAB and Simulink files and from attempting automerge.*.mlx = svn:mime-type=application/octet-stream *.mat = svn:mime-type=application/octet-stream *.fig = svn:mime-type=application/octet-stream *.mdl = svn:mime-type=application/octet-stream *.slx = svn:mime-type= application/octet-stream *.mlapp = svn:mime-type= application/octet-stream *.p = svn:mime-type=application/octet-stream *.mdlp = svn:mime-type=application/octet-stream *.slxp = svn:mime-type=application/octet-stream *.sldd = svn:mime-type=application/octet-stream *.slxc = svn:mime-type=application/octet-stream *.mlproj = svn:mime-type=application/octet-stream *.mldatx = svn:mime-type=application/octet-stream *.slreqx = svn:mime-type=application/octet-stream *.sfx = svn:mime-type=application/octet-stream *.sltx = svn:mime-type=application/octet-stream
Check for other file types you use that you also need to register as binary to avoid corruption at check-in. Check for files such as MEX-files (
.mexa64,.mexmaci64,.mexw64),.xlsx,.jpg,.pdf,.docx, etc. Add a line to theconfigfile for each file type you use. For example, add these lines.*.mexa64 = svn:mime-type=application/octet-stream *.mexw64 = svn:mime-type=application/octet-stream *.mexmaci64 = svn:mime-type=application/octet-stream *.xlsx = svn:mime-type=application/octet-stream *.docx = svn:mime-type=application/octet-stream *.pdf = svn:mime-type=application/octet-stream *.jpg = svn:mime-type=application/octet-stream *.png = svn:mime-type=application/octet-stream
Save the
configfile.
After you create or update the SVN config file, SVN treats
new files as binary. If you already have files in repositories, register them as
described in Register Files Already in Repositories.
Register Files Already in Repositories
Changing your SVN config file does not affect files already
committed to an SVN repository. If an existing file is not registered as binary,
use svn propset in command-line SVN to manually register the
files as
binary.
svn propset svn:mime-type application/octet-stream binaryfilename
Enforce Locking Files Before Editing
You can configure SVN to make files with specific extensions read-only. Users must place a lock on read-only files before editing them. When a file has a lock, other users know the file is being edited and you can avoid merge issues.
To enforce locking files, modify entries in the SVN config
file. To locate your SVN config file, see Register Binary Files with SVN.
To make files with an
.mextension read-only, add a property to your SVNconfigfile in the[auto-props]section. If there is no entry for files with an.mextension, add one with theneeds-lockproperty.*.m = svn:needs-lock=yes
If an entry exists, you can combine properties in any order, but multiple entries must be on a single line separated by semicolons.
To make files with an
.mlxextension read-only, add a property to your SVNconfigfile in the[auto-props]section. Because you must register files with an.mlxextension as binary, there is an entry for the file type. Add theneeds-lockproperty to the entry in any order on a single line and separated by a semicolon.*.mlx = svn:mime-type=application/octet-stream;svn:needs-lock=yes
Recreate the working folder for the configuration to take effect.
After you enforce file locking, users must place a lock on a file before editing the file. For more information, see Get SVN File Locks.
Share a Subversion Repository
To share a subversion repository, set up a server using the Apache™ SVN module. For more information, see https://svnbook.red-bean.com/en/1.7/svn-book.html#svn.serverconfig.httpd.
Note
In a production environment, do not rely on remote repositories via the file system using the
file:/// protocol. The file protocol is not safe. Concurrent access might corrupt repositories.MATLAB does not support interacting with remote repositories using the
svn+ssh:// protocol.