删除虚假提交父指针 [英] Remove spurious commit parent pointer

查看:16
本文介绍了删除虚假提交父指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Bazaar 存储库导入 Git(使用 git bzr),但生成的存储库包含虚假提交父链接:

请注意,标记为 1.02-6 的提交基于 1.02-3 提交,但 1.02-1 也不必要地标记为家长.(注意:回购的这一部分中的所有提交都被标记了;显示的提交之间没有提交.)

我尝试了多种方式重新定位(在 master 分支上:git rebase 1.02-3git 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 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-tree internal command.

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.

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

This created a new commit, and printed its hash (cc32e66...). Now turn it into a new branch:

git checkout -b fixed_commit cc32e66

and rebase master onto the new branch:

git checkout master
git rebase fixed_commit

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.

这篇关于删除虚假提交父指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆