A blog about software development, primarily in Java and about web applications.

Showing posts with label merge. Show all posts
Showing posts with label merge. Show all posts

Wednesday, March 6, 2013

Subversion (SVN) Merging From The Command Line

It is usually pretty straight forward to merge fixes from a branch into the trunk using SVN. Here is a SVN command line example.
  1. Check out a pristine up-to-date trunk or use a workspace with no modifications.
  2. svn merge https://svn.myorg.com/repos/devteam/myproject/branches/v7.00.4@HEAD .
    $ svn merge https://svn.myorg.com/repos/devteam/myproject/branches/v7.00.4@HEAD .
    --- Merging r110205 through r110328 into '.':
    U    src/java/edu/stanford/irt/frd/layout/StaffLayout.java
    U    src/java/edu/stanford/irt/frd/layout/Layout.java
    U    src/web/social/profileUserfeed.jsp
    U    src/web/public/menlo_profile_printer.jsp
    
  3. verify the merge fixes things locally
  4. commit the changes to the trunk. SVN will keep track of what has already been merged so that future merges are also easy to do.
    $ svn commit -m "Merging 4.0.1 bug fixes into trunk"
    Sending        .
    Sending        src/java/edu/stanford/irt/frd/layout/Layout.java
    Sending        src/java/edu/stanford/irt/frd/layout/StaffLayout.java
    Sending        src/web/public/menlo_profile_printer.jsp
    Sending        src/web/social/profileUserfeed.jsp
    

Thursday, June 9, 2011

Reverting commits with Subversion

This is actually fairly straightforward, but to do, but it came up again today at work so I thought I would document how to do it.

If you commit some changes that you want to revert immediately after the commit (before anyone else has done anything), you simply find the revision number you want to go back to and run:

$ svn merge --dry-run -rHEAD:86540 .

$ svn merge -rHEAD:86540 .

$ svn commit -m "revert to revision 86540" .


A few comments about this. You are changing your local working copy. In the above example, I'm assuming your local copy has been updated to the HEAD of your repository.

The first command is a dry-run and will show you the changes that will occur. I'm using HEAD as a shortcut, you could also specify a specific SVN revision number. Generally speaking, using HEAD is a bad idea, because HEAD is a moving target if you ware working with a team of people. So it's always best to use the specific revision number your local working copy is updated with.

The second command is the actual merge. Since the changes are being done to your local working copy, the commit is done to save your changes. You could alternately revert if something went awry.