0

After merging a branch with git merge --no-commit --no-ff feature_branch I made some additional changes, added them, and commited with git commit. So far so good. After that I wanted to push my merge commit but that failed because of no fastforward.

I used git pull --rebase=preserve to update my local branch.

The update was successfull but all changes I made were lost! Why does this happen? Is it a bug? I'm using version 1.8.5.

Reflog:

5032b06 HEAD@{6}: pull --rebase=preserve: checkout 1454216f11e60ba1de094a2e7deda6e3f1b0eb54: returning to refs/heads/dev
5032b06 HEAD@{7}: pull --rebase=preserve: checkout 1454216f11e60ba1de094a2e7deda6e3f1b0eb54: Merge made by the 'recursive' strategy.
1454216 HEAD@{8}: pull --rebase=preserve: checkout 1454216f11e60ba1de094a2e7deda6e3f1b0eb54
3c8e15c HEAD@{9}: pull --rebase=preserve: checkout 1454216f11e60ba1de094a2e7deda6e3f1b0eb54: test
1454216 HEAD@{10}: pull --rebase=preserve: checkout 1454216f11e60ba1de094a2e7deda6e3f1b0eb54
467fb1d HEAD@{11}: commit (merge): Merge branch 'moep' into dev

At 467fb1d everything is fine. Then after the pull I'm at 5032b06 with all modifications added to the merge commit being lost! This can't be right.

T3rm1
  • 2,299
  • 5
  • 34
  • 51

1 Answers1

0

--rebase=preserve passes the --preserve-merges option to rebase. Your merge commit is not a clean merge, it is an evil merge (it contains changes neither in any of the two parents).

git help pull:

When set to preserve (deprecated in favor of merges), rebase with the --preserve-merges option passed to git rebase so that locally created merge commits will not be flattened.

git rebase simply does not support replaying evil merges, it will redo the merge (equivalent to calling git merge).

That's only one of the reasons why evil merges are generally discouraged.

Corollary: don't amend merge commits!

References

Especially the last one echos your problem pretty well.

knittl
  • 246,190
  • 53
  • 318
  • 364