fake commit parent

Devoted some time today to figure out how to add a "fake" parent to a commit in git. It's quite easy once you discover there is something called grafts in git.

A graft can be created be adding a line to .git/info/grafts which is simply a list of commit-shas. The first identifies the commit to modify and the following is what the parents of that commit should be. The following adds a second parent to the commit <commit> that currently have <parent1> as it single parent.

echo "<commit> <parent1> <parent2>" >> .git/info/grafts

After doing this all commands like git log and git blame will behave as if <parent2> was a parent of <commit>. However this change is only local all will not follow after a git push.

filter-branch to the rescue

git filter-branch --tag-name-filter cat -- origin/master..