gitrebasegit-rerere

Examples of manual amendments to merge commits


git rebase --preserve-merges

The doc says that "Merge conflict resolutions or manual amendments to merge commits are not preserved".

I understand how merge conflicts can be dealt by using rerere, but what exactly are manual amendments to merge commits? Does rerere deal with this as well? If not, is there a workaround?


Solution

  • The doc says that "Merge conflict resolutions or manual amendments to merge commits are not preserved".

    What this sentence is saying (not very well) is that with --preserve-merges, git rebase actually re-does the merge.

    It's not possible in general to preserve the original merge, and Git simply does not try. Instead, it notes that original commit M was a merge with extra parent(s) p2, p3, ..., pN over and above the parent in the chain you're rebasing. So, when copying M, instead of doing git cherry-pick <ID>, it does git merge p2 .... This, of course, makes an all-new merge.

    The rebase code does not adjust your rerere settings at all, so you get whatever you have set.

    ... what exactly are manual amendments to merge commits?

    This is probably best demonstrated by example:

    $ git checkout br1
    $ git merge --no-commit br2
    Automatic merge went well; stopped before committing as requested
    $ git status --short
    A  file2
    $ echo 'sneaky sneaky' >> file2
    $ git add file2
    $ git commit --no-edit
    [br1 86ea409] Merge commit 'br2' into br1
    

    The line I added to file2 appears nowhere in either branch: I amended it manually.

    (Equivalently, I could let the merge do an auto-commit, and use git commit --amend afterward, which shoves the original merge aside and puts a new merge in place using whatever I have git added into the index since then.)