Version Control

How to delete a tag or branch in subversion

Posted in SVN on December 2nd, 2011 by Joonas – Be the first to comment

Every now and then you make a typo when creating a branch or tag. If you want to fix your mistake, use the following commands to delete your branch/tag and then you can go ahead and re-create it with the proper name.

svn delete https://svn.domain.com/svn/myproject/tags/my_mispeeld_tag_name -m "typo in tag name"
svn delete https://svn.domain.com/svn/myproject/branches/my_mispeeld_branch_name -m "typo in branch name"

You can check that your delete(s) took effect by listing the branches or tags with the following command.

svn list https://svn.domain.com/svn/myproject/tags/
svn list https://svn.domain.com/svn/myproject/branches/

How to undo/revert a commit in Subversion (SVN)

Posted in SVN, Version Control on October 27th, 2011 by Joonas – Be the first to comment

Every now and then you mess up and commit something that shouldn’t have gone out or you broke something with a bad merge. Undoing the damage is usually quite simple.

I’m going to use a sample case to explain the process. Let’s assume I have a branch called “bigchange” and I need to merge that to trunk and get it released on the web. Ok, so I do my standard svn merge and then commit my change. Then I realize that the branch had a piece of code with a syntax error in it and it breaks my entire website. I need to roll back that commit immediately from trunk.

In order to undo a commit, you need to either now the revision number to which you want to revert or you can just revert to “the previous” revision, but in that case you need to be sure that the “previous revision” is really where you want to go. Usually reverting to the “previous revision” is fine if you are the only one committing things to the repository at the time of the mess up.

To undo the commit that introduced bad code to the trunk, I would use the following command to revert to the previous revision.

svn merge --dry-run -rHEAD:PREV https://example.com/svn/myproject/trunk

That command reverts trunk from HEAD (the current revision) to PREV (the previous revision). You may have already noticed that the command has “–dry-run” in it. You should always dry-run your svn commits and merges. Dry-run will show you what the command will actually do. If the merge looked ok and the right stuff was reverted or undone, take out the –dry-run and run the real thing and commit your change.

svn merge -rHEAD:PREV https://example.com/svn/myproject/trunk
svn commit -m "reverted bad code with syntax error"

Sometimes you run in to an instance where you have made multiple commits and you need to roll back further. In this case, you need to know the revision number that you want to go back to. You can use the following command to browse for revision numbers.

svn log

Once you know the revision number (1005 for example), revert to it with the following command:

svn merge --dry-run -rHEAD:1005 https://example.com/svn/myproject/trunk

There are some other parameters you can pass to the -r attribute, check them out with:

svn merge --help

SVN – Merging Trunk to a Branch

Posted in SVN, Version Control on October 11th, 2011 by Joonas – Be the first to comment

Sometimes you run in to an instance where you have created a branch from trunk in the past, but when you go to merge it back in to trunk you get a whole lot of conflicts because things in trunk have changed since your branch was created. The solution is to update your branch by merging the latest changes from trunk to your branch.

First, switch your local working copy to your branch

The next step is to merge in all the revisions of trunk in to your branch since the branch was created. To do this, you need to find out what the last revision of trunk was that was synced with your branch. Do that by running the following command:

svn log -v --stop-on-copy

Find the earliest revision number (Ex. r1006) within the output from the svn log command. Once you have that number, you are ready to merge in all the changes from trunk. To do so, run the following command:

svn merge -r1006:HEAD https://url/to/your/repo/trunk .

You should see a lot of additions, modifications, and even deletes if a ton of things have changed in trunk since you created your branch. The command merges in all changes to trunk from revision 1006 up to the latest revision. You may run in to a conflict or two if changes in your branch overlap with changes made in trunk. You’ll have to resolve those conflicts manually.

Once you have merged in the changes from trunk and cleared any possible conflicts, commit the updates to your branch by running the following command:

svn commit -m "merged in latest changes from trunk"

Now you have merged trunk in to your branch. Now you can go on as usual and merge your branch to trunk with minimal tree and file conflicts.