Loading...

All project content is available for reading, but you need to be a member of the project for Subversion checkout of source code, or to create/modify any information.
Login if you are a member. Apply here to request membership (open to all).

Develop, Branch, Merge

The scanario that is covered by this How-To:

You've checked out your project's 'trunk' folder and are happily hacking away at fixing some issue when you realize that the changes are growing to big and/or incompatible. It really should have been made in a branch first, and merged back to trunk when completely finished and verified.

... or you just want to review the essence of how to branch and merge.

Here is how...

  1. The initial checkout...
    $> svn checkout https://www.coderesort.com/svn/open/trac-talkplugin/trunk tractalk
    
  1. Hack, hack away. Trivial difference for illustration...
    $> cd tractalk
    $> vi setup.py
    $> svn diff
    Index: setup.py
    ===================================================================
    --- setup.py	(revision 15)
    +++ setup.py	(working copy)
    @@ -8,6 +8,8 @@
     Copyright (C) 2009-2010 Odd Simon Simonsen, simon-code@bvnetwork.no
     """
     
    +# hack hack hack
    +
     from setuptools import setup, find_packages
     
     setup(name='TracTalkPlugin',
    
  1. Oh. Should have made a branch for this. Make the branch ON THE SERVER...
    $> > svn copy -m "new stuff branch" ^/trac-talkplugin/trunk ^/trac-talkplugin/new-stuff
    
  1. Now switch the local working copy to new branch (with changes pending locally)...
    $> svn switch ^/trac-talkplugin/new-stuff
    
  1. Commit the new changes to the branch...
    $> svn commit -m "the new stuff."
    
  1. More changes happens as feature is polished and changes in trunk in same period. Time to merge...
  1. First, integrate any changes that has happened in trunk by MERGING TRUNK TO BRANCH...
    $> svn update
    $> svn merge ^/trac-talkplugin/trunk
    --- Merging r18 into '.':
    U    setup.py
    $> svn diff
    
    Property changes on: .
    ___________________________________________________________________
    Added: svn:mergeinfo
       Merged /trac-talkplugin/trunk:r15-18
    
    Index: setup.py
    ===================================================================
    --- setup.py	(revision 16)
    +++ setup.py	(working copy)
    @@ -12,6 +12,8 @@
     
     from setuptools import setup, find_packages
     
    +# old stuff
    +
     setup(name='TracTalkPlugin',
           version='0.2',
           author='CodeResort.com / BV Network AS',
    $> svn commit -m "merged [18] from trunk."
    Committed revision 19. 
    
  1. Branch is now completed and updated with latest trunk changes, and ready for production. Switch back to trunk and bring in our changes from the branch...
    $> svn switch ^/trac-talkplugin/trunk
    $> svn merge ^/trac-talkplugin/new-stuff
    --- Merging r15 through r19 into '.':
    U    setup.py
    $> svn diff
    
    Property changes on: .
    ___________________________________________________________________
    Added: svn:mergeinfo
       Merged /trac-talkplugin/new-stuff:r15-19
    
    Index: setup.py
    ===================================================================
    --- setup.py	(revision 19)
    +++ setup.py	(working copy)
    @@ -8,6 +8,8 @@
     Copyright (C) 2009-2010 Odd Simon Simonsen, simon-code@bvnetwork.no
     """
     
    +# hack hack hack
    +
     from setuptools import setup, find_packages
     
     # old stuff
    
  1. Looks good and all tests pass. Commit the new stuff and remove the branch that is no longer needed...
    $> svn commit -m "integrated new stuff branch."
    $> svn delete -m "new stuff is all done." ^/trac-talkplugin/new-stuff
    

That's it. Changes done in a branch, merged back and old branch cleaned and removed. All developers happy...

Questions & Answers

Q: What is the svn:mergeinfo property that gets updated?

A: This a feature of Subversion, and Subversion uses this property to do merge-accounting. It keeps track of what revisions has been merged and from where.

Q: What is the '^' characters used in URLs?

A: It means 'root of repository', and Subversion will deduct the URL to repository from current working copy information. Less to remember and type correctly... See http://subversion.wandisco.com/component/content/article/1/20.html for summary of repository-relative URLs.