Question

Since I heard that being a lazy programmer is a virtue, I delayed the creation of my git-flow feature branch like this:

* dca9fae - Merge branch 'feature/refactor' into develop
|\
| * 9ca4bc3 - Delivery task
| * 8b2e03f - rf up Repo DSL attributes
|/
* e1ddb98 - access to self.views made private
* 0ab6725 - extract Repo#aggregate
* 9bf6ca0 - Merge branch 'feature/mapper'

I want to clean my commit history by moving up two of my refactoring commits, and get something like this:

* dca9fae - Merge branch 'feature/refactor' into develop
|\
| * 9ca4bc3 - Delivery task
| * 8b2e03f - rf up Repo DSL attributes
| * e1ddb98 - access to self.views made private
| * 0ab6725 - extract Repo#aggregate
|/
* 9bf6ca0 - Merge branch 'feature/mapper'

My original though to edit my commit history was this:

git rebase -i 9bf6ca0

Sadly that destroyed my nice non-fast-forward merge bubble and flattened the whole thing into something like this:

* dca9fae - Merge branch 'feature/refactor' into develop
* 9ca4bc3 - Delivery task
* 8b2e03f - rf up Repo DSL attributes
* e1ddb98 - access to self.views made private
* 0ab6725 - extract Repo#aggregate
* 9bf6ca0 - Merge branch 'feature/mapper'

How can I make git rebase to preserve my non-fast-forward merges?

I am interested not only in how to obtain my second example starting from the first example, but also starting from the third one.

Was it helpful?

Solution

Basically you could do it like this:

git reset --hard 9ca4bc3
git merge --no-ff 9bf6ca0

Unfortunately you did tell, where your branches currently point to. Probably what you really want is something like this:

git checkout refactor
git reset --hard 9ca4bc3
git checkout develop
git reset --hard 9bf6ca0
git merge --no-ff refactor

You also did not specify where your upstream branches point to. Watch out not to change any commits already published.


git rebase does not make sense in your case. It just takes your commits and adds them to the new base. In your case the old base seems to be exactly the same as the new base, therefore the result is exactly the same as before. (Only the merge commit is missing.)

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