SVN is a version control system often used by programmers to keep track of versions or changes of code. It makes it easy collaborate on code projects and keep a backup of every change you’ve made. Following are some common tasks you may need to perform.
Checking out trunk
This copies files from your trunk folder in SVN to a folder on your local computer. The folder on your local computer is your “working copy” where you make changes.
Updating your local working copy
If you are working on a project with someone else, for example, and they have make code changes which they have committed to trunk in SVN, then you can get their changes by updating your local working copy of trunk. This will merge their changes into your local working copy files and if there’s a conflict, you would need to resolve them.
Resolving conflicts
If your changes conflict with other people’s changes, e.g. you’re changing a line of code that other people have changed, then there will be a conflict. You will need to resolve this conflict by choosing which version of the code to keep.
Adding a new “unversioned” file
When you create a new file in your local working copy, its status will appear as “unversioned”. In order to save this file in version control, you will need to “add” it and then commit it.
Previewing changes
If you’ve modified a file in your local working copy, its status will appear as “modified”. You can click on it to show a diff of the changes you’ve made.
Reverting local file changes
If you’ve made changes to a file in your local working copy but you no longer want to keep those changes, you can revert the file bring it back to its state before you made any changes to it.
Deleting a file from SVN
Committing changes from your local working copy to SVN / trunk
If you’re happy with the additions (new files) and modifications you’ve made to files you’ve made in your local working copy, you can commit these changes / files to SVN which saves those changes and marks it at a particular revision. It’s good to do frequent commits.
Reverse merging / rolling back (undoing) to a previous revision
If you’ve made a mistake in some files that you’ve committed to SVN, you can undo those changes by doing a “reverse merge”. You can reverse merge from HEAD to the revision just before HEAD or to several revisions before HEAD. Or, you can reverse merge just changes in one revision several revisions before HEAD. SmartSVN’s reverse merge is inclusive so reverse merging from 13093-HEAD will undo changes in your local working copy including the changes you made in revision 13093.
Inclusive 13093-HEAD
You can also reverse merge a file by viewing its revision graph
and then right-clicking on the revision you want to roll back to.
If you want to reverse merge just one file within a revision, when looking at the revision graph, select that file in the list of files in the revision and click the Rollback button.
Creating a patch
Select a folder or a file and then click Query > Create Patch.
Applying a patch
Click Modify > Apply Patch.
Exporting
Exporting is similar to checking out except it doesn’t create a working copy under SVN control. It simply copies files from SVN to your local computer without a version control or history.
Creating a branch of trunk
If you need to make big changes to your trunk that will take a while to complete, it’s best to create a branch and make your changes there. For example, if you’re adding a big new feature to your website, you can create a branch for this new feature. To create a branch of trunk, copy the entire trunk folder. Don’t create a folder in the “branches” folder and then copy each subfolder in trunk into the new folder in the “branches” folder.
Checking out a branch
Cherry-pick merging certain revisions from trunk to your branch working copy
Sync merging all revisions from trunk to your branch working copy
If you’ve made some changes in trunk that you’d like to merge into your branch working copy and you want to merge ALL changes from trunk, then you can do a “sync merge”. If there are any conflicts, you will need to resolve them. After you do a sync merge, it’s good to do a commit.
Re-merging a revision that was already merged
Sometimes, for some unknown reason, you merge a bunch of revisions only to find that some file in some revision didn’t get merged in. You may try to do the merge again for the revision containing the missing file, but SVN will tell you that that revision was already merged in. To get around this and solve the problem, you can do the merge again but also check the “Ignore Ancestry” checkbox in the Advanced tab of the Merge dialog box. This will tell SVN to ignore the fact that it already merged this revision so that you can redo the merge and pull in the missing file. I’m not sure why this happens but it doesn’t sometimes. It just happened to me today.
Reintegrating from your branch to trunk
- If your trunk working copy is not clean (it has modified files), it’s safer to check out trunk into a new, temporary folder and perform the reintegration from the branch into the temporary folder. Then, commit the entire temporary working copy to SVN trunk and do an update on your original trunk working copy.
Reintegration Merge Steps
- commit all changes from branch WC to SVN
- sync merge trunk to branch WC
- commit branch WC to SVN
- check out new copy of trunk to create a clean WC of trunk
- reintegrate merge the branch to the clean WC of trunk
- commit the clean WC of trunk to SVN
- update original (modified) WC of trunk
- delete the branch
Saving copies of a vendor files in the vendors folder, e.g. different versions of jQuery
Applying a patch between 2 different versions of a vendor’s code to your trunk working copy
SVN properties
Coming soon …
Resolving Tree Conflicts
When performing a merge operation, if you get a tree conflict, you can resolve it by selecting “Mark Resolved” on the parent folder and choosing “Only this directory (Leave as is)”.
Resolving Local State: Removed, Remote State: Unchanged Conflict
When performing an update, if you get this conflict, revert the parent folder and redo the update.