Question

I know there are lots of questions on SO about this, but I can't seem to find the answer I'm looking for at all.

I just merged my task branch into my master, and I am ready to push my changes to the remote master branch. However, they are displaying as two commits:

    commit 878c07412aab6a6b06b7fc8dd84c2418cc4f31d8
Merge: 9ffa590 c9f5552
Author: ***
Date:   Mon May 21 16:02:36 2012 +0100

    Merge branch 'modelUpdate4'

    Conflicts:
        ***.xcodeproj/project.pbxproj

commit c9f5552862872673317701c3dffd7fb6b6daa02c
Author: ***
Date:   Mon May 21 15:03:21 2012 +0100

    Modified model according to requests.  Repopulated seeded database.

This is the output of git log and the two commits I wish to squash as one. However, when I do:

git rebase -i HEAD~2

It actually just displays 4 previously committed (and pushed) commits. Am I misunderstanding how my branches are merged back? If I try and git rebase -i This just displays the first commit in the git log list.

Thanks!

Was it helpful?

Solution

Since you said four commits were already pushed, I'm guessing your graph (git log --oneline --decorate --graph) looks something like this, where you've got branching commits between master and modelUpdate4 already pushed to the remote repo:

* (master, modelUpdate4, HEAD) Merge branch 'modelUpdate4'
| \
|  * (origin/modelUpdate4) Modified model according to requests. [HEAD^2]
|  |
|  * Another commit on modelUpdate4
|  |
|  * Yet another commit on modelUpdate4!
|  |
*  | (origin/master) Something that conflics with a commit in modelUpdate4 [HEAD~1]
| /
* Previous commit on master [HEAD~2]

HEAD~2 is the first parent of the first parent, and since your HEAD is a merge of modelUpdate4 into master, it refers to two commits down the master line. HEAD^2 is HEAD's second parent, so the commit before HEAD down the modelUpdate4 line. (See also: http://paulboxley.com/blog/2011/06/git-caret-and-tilde)

If HEAD~2 is your new base, you'll get all the commits between HEAD~2 and master in a straight line. You'll also have to deal with the branch conflict in the modelUpdate4 commit where it happens.

* (master, HEAD) Merge branch 'modelUpdate4'
|
* Modified model according to requests.  Repopulated seeded database.
|
* Another commit on modelUpdate4
|
* Yet another commit on modelUpdate4!
|
* Something on master that conflics with modelUpdate4
|
* Previous commit on master

If anyone else is using those remote branches, or you want to maintain your branching history, don't rebase. It'll rewrite history that's already in the remote repo, which will just be a headache for everyone else. Push the merge commit out and you'll be golden.

Alternatively, you could rebase directly onto origin/master. origin/modelUpdate4 would end up out in the git boonies, but since it's a task branch I'm betting you were just going to delete it anyway.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top