About this blog

Save duplicate questions from disappearing from Google

git fake merge (marking a commit as merged without a real merge)

Question

Assume I have the following history in my repository:

     E--F
    /
A--B--C---D

And I want to modify it to be this:

     E--F
    /    \
A--B--C---D

I don't want to modify file content of revisions, I just want to "draw a merge arrow". How can I do this?

I tried to do this by the following commands:

git checkout D
git merge F -s ours --no-ff --no-commit
git commit --amend

But I got the following error message:

fatal: You are in the middle of a merge -- cannot amend.

I want to leave the commit information unchanged (author, date, message). The only thing I want to change is to add pseudo merge-info to the commit.

Answer

This worked for me:

git checkout D~1
git merge F -s ours --no-ff --no-commit
git cherry-pick D -n
git commit -C D
git branch -f D
git checkout D