Git删除根提交 [英] Git remove root commit
问题描述
我不能用git做很多事情,我想从我的repo中删除一个提交,因为我上传了错误的东西。
我用 git revert< commit_commit>
但由于提交是root,我无法删除它。
致命:无法恢复根提交
在这种情况下该做什么?
请不要给我链接到其他主题,我阅读它们,我不明白该怎么做,我需要一些关于删除一些提交的基本示例。 方案
为了移除根提交,您只需删除所有可用的分支(和标签)。
这可以完成与 git分支-D分支名称
。 (你必须首先检查另一个没有引用这个根提交的分支,因为你不能删除当前的分支,我想。)
如果你想要保留这个分支上的其他提交,并且只删除根目录, git filter-branch
更好,请参阅Greg的回答。
I can't do a lot of things with git and I want to remove a commit from my repo, because I uploaded wrong stuff.
I used git revert <the_commit>
but since the commit is root and I can't remove it.
fatal: Cannot revert a root commit
What to do in that case ?
Please don't give me links to other topics here, I read them and I don't understand what to do, I need some basic example about removing some commit.
For removing a root commit, you simply have to remove all branches (and tags) from which it is reachable.
This can be done with git branch -D branch-name
. (You will have to first check out another branch which does not refer to this root commit, since you can't remove the current branch, I think.)
If you want to retain other commits on this branch and only remove the root, git filter-branch
is better, see the answer from Greg.
这篇关于Git删除根提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!