Wednesday, June 24, 2009

Merge from trunk to branch

Everytime I had to merge some changes from trunk to a branch I spend time on re-learning the commands, so here is my attemp to etching it on the "Internet" so that I don't forget.

Note: The below commands are run from the root working copy location.

STEP 1:
======
prompt>> svn log --stop-on-copy

The command svn log will give you a complete history of comments on a branch, --stop-on-copy would tell the command to stop at a point where the current trunk was made into this branch. For now, lets say note down that revision number or the revision number where the last merge from the trunk was done. Lets assume revision 100 was the revision when this branch was created from the trunk or when the last merge from trunk was done. So, technically we need to merge all the changes in the trunk from 100 upwards.

STEP 2:
======
prompt>>svn merge r:HEAD --dry-run
where
revision_no ==> is the starting revision number to start the merge from
HEAD ===> tells svn to show all the changes from revision_no till the HEAD(which is the last revision) of the branch.
--dry-run ==> tells svn merge command to just give you a list of changes that would be made and not actually make the changes
==> In our case the url to the trunk where we are merging from
==> the working copy location.

so, translating the above to it would be something like

svn merge -r100:HEAD --dry-run svn+ssh://office.mycompany.com/data/svn//project/current/trunk/ .

This would show you a list of files that would be changed and what would be the status. For instance, if there are two files A.java and pom.xml that would be merged, a third file C.java that has a conflict and two files D.java and E.jsp that were added to trunk, it would come up as

M A.java
M pom.xml
C C.java
A D.java
A E.jsp

Remember, you had run the svn merge command with the option of --dry-run, so the actual merge hasn't taken place yet. So, if you feel confident about the changes coming in, run the same command as shown above but this time without the --dry-run option. svn would merge the changes and show the same result as above.

The important step now is that when you commit the above changes do it with a comment of that is informative like "All changes were merged from Trunk". Why? Because lets say down the line after a month or so, and you are again ready to merge changes from the trunk, you can just start from this checked in revision and not do the merge from all the way back at the start of the branch.

It would be nice if svn merge command would be able to figure this out instead of us keeping track from the comments, but at this time that seems to be the only option.

No comments:

Post a Comment