git - duplicate parent

霸气de小男生 提交于 2019-12-10 23:26:28

问题


I seem to have managed to have a commit with two duplicate parents using eGit (Eclipse's git client, powered by JGit).

The 2nd parent causes that green 'branch to nowhere' that we can't get rid of.

I've been googling ways to perform some surgery on the commit to remove the extra parent, but to no avail.

Running cat-file I get:

$ git cat-file -p 26dc6a5b44373f766d81513ab84c5eecaf876736

tree 527df208ee66f52bc414948b1de0fa6607cfb81c
parent bc9d55d0451b325b4ad5a758be8b30c1418b3af9
parent bc9d55d0451b325b4ad5a758be8b30c1418b3af9
author Roy Truelove <roy.truelove@xxxx.com> 1316457571 -0400
committer Roy Truelove <roy.truelove@xxxx.com> 1316457571 -0400

I'm sharing this repo and this problem has already been pushed, which I'm sure will contribute to the complexity of the solution..

Thanks git hackers, Roy

PS - I do have command line access to this repository (cygwin) if I need to perform a function not available through eGit


回答1:


You can use git filter-branch to rewrite the history; the duplicate parent will automatically be corrected.




回答2:


In order to remove the duplicate parent from the commit you can do this:

git replace <sha1> $(git cat-file commit <sha1> | uniq | git hash-object -t commit -w --stdin)

The commit with the duplicate parent has been temporarily replaced with a new commit that does not contain the duplicate parent. You can check if the gitk display problem has gone away now.

In order to permanently replace the commit you can use git filter-branch. Note that at that point you will have rewritten history. All developers working on this project must be made aware of this, so that they can also rebase/reset their local work/copies to the new history.



来源:https://stackoverflow.com/questions/7489713/git-duplicate-parent

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!