-
Notifications
You must be signed in to change notification settings - Fork 14
Merging a SVN branch
When you want to merge your changes into the master branch, you'll want to use a rebase with master. Rebasing avoids merge commits in the history and is best explained illustrated (notice it's similar to git svn rebase). The workflow below describes branching, merging mainline into the branch, merging the branch into mainline (blue are mainline commits, green are branch commits, yellow are merge commits):

Let's work through a simple example.
-
First lets create a branch in SVN (use a unique name other than test-branch), make a change, and commit it to the branch. Note that
git checkout -bis short form forgit branch <local branch>; git branch --set-upstream <local branch> <remote branch>; git checkout <local branch>% git checkout -b local/test-branch test-branch Switched to a new branch 'local/test-branch' % git log commit aa375997807e036421f7b16f0c2957174b7c56fc Author: abhik@branchout.com <abhik@branchout.com@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 15:53:16 2011 +0000 Test Branch git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/branches/test-branch@15 ba991f9a-d5de-4771-8651-3090c57d9f48 commit 541cbcdedffaf2176baf8f5776763b60892d6d17 Author: abhik@branchout.com <abhik@branchout.com@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 15:44:29 2011 +0000 Adding a line to INSTALL through git. git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk@14 ba991f9a-d5de-4771-8651-3090c57d9f48 ... % echo "Hi" >> README % git commit -am "Adding a line from a git branch." [local/test-branch 394094f] Adding a line from a git branch. 1 files changed, 1 insertions(+), 0 deletions(-) % git svn dcommit Committing to https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/branches/test-branch ... M README Committed r16 M README r16 = 5237722de8359ac7d6980b2b07118196801af8a9 (refs/remotes/test-branch) No changes between current HEAD and refs/remotes/test-branch Resetting to the latest refs/remotes/test-branch % git log commit 5237722de8359ac7d6980b2b07118196801af8a9 Author: abhik@branchout.com <abhik@branchout.com@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 19:48:49 2011 +0000 Adding a line from a git branch. git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/branches/test-branch@16 ba991f9a-d5de-4771-8651-3090c57d9f48 commit aa375997807e036421f7b16f0c2957174b7c56fc Author: abhik@branchout.com <abhik@branchout.com@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 15:53:16 2011 +0000 Test Branch git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/branches/test-branch@15 ba991f9a-d5de-4771-8651-3090c57d9f48 ... -
Now let's make a change in mainline so it has commits that the branch does not have.
% git checkout master Switched to branch 'master' % echo "Change from mainline" >> README % git commit -am "Change from mainline" [master 9f6732d] Change from mainline 1 files changed, 1 insertions(+), 0 deletions(-) % git svn dcommit Committing to https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk ... M README Committed r17 M README r17 = 219b90dabdd2742dbce808add1a401ca9aca6a30 (refs/remotes/trunk) No changes between current HEAD and refs/remotes/trunk Resetting to the latest refs/remotes/trunk % git log commit 219b90dabdd2742dbce808add1a401ca9aca6a30 Author: abhik@branchout.com <abhik@branchout.com@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 20:02:50 2011 +0000 Change from mainline git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk@17 ba991f9a-d5de-4771-8651-3090c57d9f48 commit 541cbcdedffaf2176baf8f5776763b60892d6d17 Author: abhik@branchout.com <abhik@branchout.com@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 15:44:29 2011 +0000 Adding a line to INSTALL through git. git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk@14 ba991f9a-d5de-4771-8651-3090c57d9f48 ... -
Switch back to the branch and lets begin the rebase. You'll get a conflict with your change. Resolve it normally.
% git checkout test-branch Switched to branch 'test-branch' % git rebase master First, rewinding head to replay your work on top of it... Applying: Adding a line from a git branch. Using index info to reconstruct a base tree... Falling back to patching base and 3-way merge... Auto-merging README CONFLICT (content): Merge conflict in README Failed to merge in the changes. Patch failed at 0001 Adding a line from a git branch. When you have resolved this problem run "git rebase --continue". If you would prefer to skip this patch, instead run "git rebase --skip". To restore the original branch and stop rebasing run "git rebase --abort". % gvim README % git add . % git rebase --continue Applying: Adding a line from a git branch. % git log commit 9e2f61a2ea3d5906d53ce62bb5f0774b0b9c73f2 Author: abhik@branchout.com <abhik@branchout.com@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 19:48:49 2011 +0000 Adding a line from a git branch. git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/branches/test-branch@16 ba991f9a-d5de-4771-8651-3090c57d9f48 commit 219b90dabdd2742dbce808add1a401ca9aca6a30 Author: abhik@branchout.com <abhik@branchout.com@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 20:02:50 2011 +0000 Change from mainline git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk@17 ba991f9a-d5de-4771-8651-3090c57d9f48 ... -
With the rebase, the branch should be a commit ahead of master. Switch to master and perform a merge. Since the branch has only commits ahead of master it will perform a fast forward merge.
% git checkout master Switched to branch 'master' % git merge local/test-branch Updating 219b90d..9e2f61a Fast-forward README | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) % git log commit 9e2f61a2ea3d5906d53ce62bb5f0774b0b9c73f2 Author: abhik@branchout.com <abhik@branchout.com@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 19:48:49 2011 +0000 Adding a line from a git branch. git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/branches/test-branch@16 ba991f9a-d5de-4771-8651-3090c57d9f48 commit 219b90dabdd2742dbce808add1a401ca9aca6a30 Author: abhik@branchout.com <abhik@branchout.com@ba991f9a-d5de-4771-8651-3090c57d9f48> Date: Thu Sep 15 20:02:50 2011 +0000 Change from mainline git-svn-id: https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk@17 ba991f9a-d5de-4771-8651-3090c57d9f48 ... -
Now you can simply
dcommitto SVN to complete the merge.% git svn dcommit Committing to https://pl3.projectlocker.com/BranchOut/SvnTestRepo/svn/trunk ... M README Committed r18 M README r18 = af9fdb795b3634cb37e7d27bfea848bc231b3ecc (refs/remotes/trunk) No changes between current HEAD and refs/remotes/trunk Resetting to the latest refs/remotes/trunk