I imported a Bazaar repository into Git (using git bzr), but the resulting repository contains a spurious commit parent link:

Notice that the commit tagged 1.02-6 is based off the 1.02-3 commit, but 1.02-1 is unnecessarily also marked as a parent. (Note: All the commits in this part of the repo are tagged; there are no commits between the ones shown.)
I have tried rebasing in several ways (on the master branch: git rebase 1.02-3, git rebase -i upstream-1.02, git rebase --onto 1.02-1 1.02-3, git rebase --root upstream-1.02 --onto=other_branch), but in each case it fails with a merge conflict. These seem to be attempting more than is necessary; the history is correct except for an extra parent pointer being recorded in the commit tagged 1.02-6.
How do you remove the link in order to linearize the history? Is there a better way than manually cherry-picking all the commits in sequence?
You can do it manually using the
git commit-treeinternal command.We want to edit the commit tagged
1.02-6to remove the spurious parent pointer (to56a2f3b5948ab54c9239c2b384a6ea9eb1f410c4).First, read the information from the existing commit object:
Extract the commit message using
git log --format=%B -n 1 1.02-6.Now create a new commit with the same content (excluding the spurious parent link, and the committer info):
This created a new commit, and printed its hash (
cc32e66…). Now turn it into a new branch:and rebase
masteronto the new branch:And we’re done:
You probably want to delete the old branches and re-tag the appropriate commits.
Actually it might be easier to use
git filter-branch --parent-filter. I haven’t tried that.