删除虚假的提交父指针 [英] Remove spurious commit parent pointer
问题描述
我将Bazaar存储库导入到Git中(使用git bzr
),但是生成的存储库包含虚假的提交父链接:
I imported a Bazaar repository into Git (using git bzr
), but the resulting repository contains a spurious commit parent link:
请注意,标记为1.02-6
的提交是基于1.02-3
提交的,但是1.02-1
也不必要地被标记为父级. (注意:回购此部分中的所有提交均已标记;显示的提交之间没有任何提交.)
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.)
我已经尝试了几种方式进行基础调整(在master
分支上: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
),但是在每种情况下,合并失败都会失败.这些似乎正在尝试不必要的尝试.历史是正确的除了,因为在提交标记为1.02-6
的提交中记录了一个额外的父指针.
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?
推荐答案
您可以使用 git commit-tree
内部命令.
You can do it manually using the git commit-tree
internal command.
我们要编辑标记为1.02-6
的提交,以删除虚假的父指针(指向56a2f3b5948ab54c9239c2b384a6ea9eb1f410c4
).
We want to edit the commit tagged 1.02-6
to remove the spurious parent pointer (to 56a2f3b5948ab54c9239c2b384a6ea9eb1f410c4
).
首先,从现有的提交对象中读取信息:
First, read the information from the existing commit object:
user@host:/path/repo.git$ git cat-file -p 1.02-6
tree c658aa1ebcf2bf2a607696c7868b875be72fb01f
parent 56a2f3b5948ab54c9239c2b384a6ea9eb1f410c4
parent 4e671bf1d2298729c9e5cfd8229051cfe2c40831
author James Damour (Suvarov454) <suvarov454@users.sourceforge.net> 1146319620 -0400
committer Bazaar Package Importer <james.westby@ubuntu.com> 1146319620 -0400
The "main/" in the Section line of debian/control should be assumed.
使用git log --format=%B -n 1 1.02-6
提取提交消息.
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):
git log --format=%B -n 1 1.02-6 | \
GIT_AUTHOR_NAME="James Damour (Suvarov454)" \
GIT_AUTHOR_EMAIL="suvarov454@users.sourceforge.net" \
GIT_AUTHOR_DATE="1146319620 -0400" \
git commit-tree c658aa1ebcf2bf2a607696c7868b875be72fb01f \
-p 4e671bf1d2298729c9e5cfd8229051cfe2c40831
这将创建一个新的提交,并打印其哈希值(cc32e66
...).现在将其变成一个新分支:
This created a new commit, and printed its hash (cc32e66
...). Now turn it into a new branch:
git checkout -b fixed_commit cc32e66
并将master
重新设置到新分支上:
and rebase master
onto the new branch:
git checkout master
git rebase fixed_commit
我们完成了:
您可能想要删除旧的分支,然后重新标记适当的提交.
You probably want to delete the old branches and re-tag the appropriate commits.
实际上,使用 git filter-branch --parent-filter
可能会更容易.我还没有尝试过.
Actually it might be easier to use git filter-branch --parent-filter
. I haven't tried that.
这篇关于删除虚假的提交父指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!