Search This Blog

Monday, September 17, 2012


How do I fix my merge tree to look nice?

Make sure you did the prior exercise so you have merge_client.  Clone the merge_client so you can play around and if necessary delete everything and start over.

git clone merge_client fix_merge_client
cd fix_merge_client

Before we rebase we want to find the commit number for our Initial README change.

git log --oneline

In my log it looks like this:


575c05f Merge branch 'master' of /Users/justsomeguy/google/projects/gitmigration/tmp/
dc7347b client1-README2
1dcfd87 Merge branch 'master' of /Users/justsomeguy/google/projects/gitmigration/tmp/
33d11e5 client1-readme
3526271 merge-readme
3984243 Initial README


Now we are going to rebase it to put our commits in order and remove the bonus merges we don't want.

git rebase -i --onto 3984243 HEAD~3

That means we are going to look at the last 3 real commits (non-merge) from HEAD, in other words client1-README2, merge_client, and client1

In the editor move the pick for merge_client to the end.  This will reorder the patches to give us the nice streamlined no branch we saw in rebasing.

git helpfully responds with this message:

The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

   git commit --allow-empty

Otherwise, please use 'git reset'
# Not currently on any branch.
nothing to commit (working directory clean)
Could not apply 9dc94e6... client1

This is a confusing message because what it's saying is that it doesn't need to do anything, which is actually what you want.  Just continue:

git rebase --continue

This leads to a merge conflict:

error: could not apply 71f6c62... merge_client

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To check out the original branch and stop rebasing run "git rebase --abort".
Could not apply 71f6c62... merge_client


We expected that, after all we know it's a conflict.  Go ahead and merge it like before with:

git mergetool
git rebase --continue

You should get a request for a git commit message, the default should be fine.

verify the changes now look clean with

git log --oneline

Notice the extra merge commits are now out of the HEAD and the merge order is consistent with rebase_client

No comments:

Post a Comment