Work with Files Under SVN in MATLAB
You can use Subversion® (SVN) source control in MATLAB® to manage your files and collaborate with others. Using SVN, you can track changes to your files and recall specific versions later.
After you check out an existing repository, you can add files to SVN source control and commit changes from the Files, Project, and Source Control panels. If the Source Control icon is not in the sidebar, click the Open more panels button and select the Source Control panel.
Download an example under SVN source control using the Copy Command button.
Check Out Files from SVN Repository
You can check out files from a remote SVN repository using the https://
or the file://
protocols.
1. On the Home tab, in the File section, select New > SVN Checkout. Alternatively, in the Files or Project panel, right-click the white space and select Source Control > Check Out SVN Repository.
2. In the Check Out SVN Repository dialog box, specify the URL.
An example URL to check out from
trunk
ishttps://svn.example.com/repos/TeamRepos/TeamUtilities/trunk
.An example URL to check out a tagged version of the repository is
https://svn.example.com/repos/TeamRepos/TeamUtilities/tags/1.1.0
. You must use the standard folder structure in your repository. For more information, see Use Standard SVN Repository Structure.An example URL to check out from a branch folder is
file://var/svn/repos/TeamRepos/TeamUtilities/branches/Release2024
. You can check out from a branch, but the built-in SVN integration does not support branch merging. Use an external tool such as TortoiseSVN to perform branch merging.
3. Specify the folder location of your working copy. The folder must be empty.
Use local folders. Using a network folder with SVN slows source control operations.
4. Click Check Out. If prompted, enter your login information for the remote repository. MATLAB, by default, remembers your usernames and passwords when you interact with SVN repositories. For information on how to disable credential management, see Configure SVN Settings.
To delete saved login information for an SVN repository, in the Files or Project panel, right-click the white space and select Source Control > Clear Credentials. Alternatively, in the Source Control panel, click the More source control options button and select Clear Credentials.
Get SVN File Locks
When you set up source control, you can configure SVN to make files with certain 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. For more information, see Enforce Locking Files Before Editing.
To check out a read-only file, in the Files or Project panel, right-click the file and select Source Control > Lock File. A lock symbol
appears in the source control status column. Other users cannot see the lock symbol in their working folders, but they cannot get a file lock or check in a locked file.
To view or break locks, in the Files or Project panel, from the top-level working folder, right-click the white space and select Source Control > SVN Locks. In the SVN Locks dialog box, you can view files that have locks and the locks owners. To break a lock, right-click a file and click Break Lock.
To remove stale locks when SVN reports a
working copy locked
error, right-click the white space and select Source Control > SVN Cleanup.
Mark Files for Addition to SVN Source Control
When you create a new file in a folder under source control, the Not Under Source Control symbol appears in the status column of the Files panel.
To add files to source control, select and right-click the files you want to add. Then, select Source Control > Add to Source Control. The source control status changes in the source control column to Added .
If you use MATLAB projects to manage the files in the folder, MATLAB automatically adds all files with the status In project to source control.
Tip: As a design grows, managing referenced files and dependencies becomes more complicated. MATLAB Projects help you organize large hierarchies by finding required files, managing the path, creating shortcuts, and sharing files and settings. For more information, see Projects.
For large working folders, use the Source Control panel to view only the list of untracked files.
To add a file to source control, in the Untracked Files section, right-click a file and select Add to Source Control.
To add a folder and its content to source control, in the Untracked Files section, right-click the folder and select Add Untracked Files. In the Add Files dialog box, clear the files that you do not want to add to source control and click Add.
To add all untracked files in the working folder to source control, click the More source control options button
. Then, select Add Untracked Files. In the Add File dialog box, select everything and click Add.
Update SVN File Status and Revision
To refresh the source control status of files and the icons in the source control column, right-click one or more files in the Files or Project panel and select Source Control > Refresh.
To refresh the status of all files in a folder, right-click the white space in the Files or Project panel and select Source Control > Refresh. Alternatively, in the Source Control panel, click the More source control options button and select Refresh.
Refreshing the SVN source control status does not contact the repository to get the latest file revisions. To get the latest file revisions, you must update your working folder using one of these options:
To update the local copies of selected files, select one or more files in the Files or Project panel, right-click and select Source Control > Update.
To update all files in a folder, right-click in the Files or Project panel and select Source Control > Update. Alternatively, in the Source Control panel, click the Update button
.
If you and another user change the same file in different SVN working folders, updating the working folder before you commit your changes might result in conflicts. For help resolving conflicts, see Resolve SVN Source Control Conflicts.
Review Changes in SVN Source Control
The source control status of every file that contains changes displays the Modified symbol . To review changes before you commit them to SVN, in the Files or Project panel, right-click a modified file and select Source Control > View Changes.
To view only the list of modified files in large working folders, use the Source Control panel instead. To view local changes in these files, right-click a file and select View Changes.
You can also compare different revisions. In the Source Control panel, right-click a file and select Show Revisions. In the Log for file dialog box, select two revisions and click Compare Selected.
The Comparison Tool opens a side-by-side comparison. For more information, see Compare Text Files and Model Comparison (Simulink).
Commit or Revert Changes to Modified Files
Before you commit modified files, review your changes and mark any new files for addition into source control.
To commit the Added and the Modified
files, In the Source Control panel, click Commit. Alternatively, in the Files or Project panel, right-click and select Source Control > Commit.
In the Commit Changes dialog box, enter the commit message and click Commit.
If you cannot commit because the repository has moved ahead, you must first update the revision to the current HEAD revision. In the Source Control panel, click the Update button
. Resolve any conflicts before you commit.
Tip: You can configure MATLAB® to prompt you about unsaved changes before performing source control actions such as commit and update. For more information, see Configure Source Control Settings.
You can also discard changes you made instead of committing them to source control.
The source control status changes from Added and Modified
to Unmodified
.
Discard Changes in Modified Files
Discarding changes releases any locks and reverts the revision to the last update.
To discard local changes in a file, in the Source Control panel, right-click a file and select Discard Changes. Alternatively, in the Files or Project panel, right-click a file and select Source Control > Discard Changes.
To discard all local changes, in the Source Control panel, click the More source control options button
and select Discard All Changes.
To revert a file to a specific revision, in the Source Control panel, right-click a file and select Show Revisions. In the Log for file dialog box, select the revision you want to revert to and click Revert.