Showing posts with label svn. Show all posts
Showing posts with label svn. Show all posts

Sunday, August 5, 2012

SVN: Merging a Branch to Trunk

svn merge - apply the changes between two sources to a working copy path

Usage:
    svn merge <source> -r<X>:<Y> <dest>
where X is the revision from where your branch was copied, and Y is the revision you want to merge your branch into.  The value of Y is usually the latest revision of trunk, or HEAD.

Switching a branch back to trunk
Note:  \ means that the command continues on to the succeeding line/s.
  1. Get the revision number from when your branch was created.
    • Option 1:  switch to the branch, and find the revision your branch began at:

           svn switch http://examplesvn.com/svn/  \
                project/branches/branch_name

           svn log --stop-on-copy

      This will display the commits that have been made in branch_name back to the point it was created.  The oldest revision here will be used as the value of X.

    • Option 2:  find the revision your branch began at without switching:

           svn log --stop-on-copy http://examplesvn.com/  \
                svn/project/branches/branch_name


      This, too, will behave the same way as option 1.

  2. Switch to destination, in this case, trunk.

         svn switch http://examplesvn.com/svn/project/trunk

  3. Test-run the merging.

         svn merge http://examplesvn.com/svn/project/  \
              branches/branch_name -rX:HEAD . --dry-run


    where X is the revision when branch_name was created, and HEAD (the actual string, not a representative of a value) is the latest revision of your current working copy, trunk, which is also your destination set to ".".  This command will simulate the actual merging, display the conflicts, if any (this is what you want to watch out for), and the rest of the changes to be made if this was an actual merge.

    Note.  This is actually a good practice, since you will see what's going to happen upon merging, without the risk of destroying your current working copy.

  4. Merge.  If the dry-run is successful and looks good to you, proceed with merging:

         svn merge http://examplesvn.com/svn/project/  \
              branches/branch_name -rX:HEAD .


  5. Check status.  Check if the changes are reflected.

         svn status

  6. Commit.  If everything is ok - changes are reflected, conflicts have been resolved, etc - commit the current changes by the merge.

         svn commit -m "MERGING branches/branch_name to trunk"

And that's it. :)


      Thursday, July 26, 2012

      SVN Switch

      svn switch (sw) - update your working copy to a different URL.

      Usage:
           svn switch <source> <dest>
      or
           svn switch <source>
      if the destination is your current location.

      Examples:
      Switching the entire working copy:
           svn switch http://examplesvn.com/svn/project/trunk
           svn sw http://examplesvn.com/svn/project/branches/branch_name

      You can also choose to switch only a part/directory of your working copy:
           svn sw http://examplesvn.com/svn/project/branches/branch_name/subdir

      Important!  When switching, always be in the directory that you want to switch; if you want to switch your entire working copy, then be in the top-level directory of your working copy.

      Why switch?  It's convenient!  When working on multiple branches of your project, you don't need to checkout each branch to a different directory or location.  Also, since switch works like update, your local changes will also be preserved when you switch.

      However, although this may be the case, I personally think it is better that you commit your local changes first before switching, because you'd want to avoid..

      The S Status
      Files with the S status (when you do a svn status) are from a different version - from a different location in your repository than the directory containing them.  This usually happens when svn switch gets interrupted in the middle, because it somehow gets confused from the local changes or conflicts.


      As a final note, here are the things you'd want to think of first before switching:
      • svn info - check the URL your working copy is currently in
      • svn status (st) - check for local modifications, conflicts, or the S status
      • commit local changes first, to avoid conflicts and unexpected behaviors