从git存储库中删除未提交的提交 [英] Remove an unreferenced commit from git repository
问题描述
U
/
A --- B --- C --- D --- E master
没有指向提交 U
,但我知道它的散列。我如何从存储库中完全删除这个提交,就好像它从来没有存在过?我是唯一使用这个回购的人。
我试过使用 git rebase
,但可以删除零件的分支或移动提交,但似乎无法删除单个提交。
如果我执行 git checkout< hash> ;
,然后 git reset --hard HEAD〜1
我没有看到提交。它实际上完全消失了还是仍然隐藏在repo中?
最终它会被git清除,但是你可以查看 git gc
实际上强制垃圾收集。
$ b clean
命令是不同的,而code>
I have a git commit history like this:
U
/
A---B---C---D---E master
Nothing points to the commit U
, but I know its hash. How can I completely remove this commit from my repository as if it never existed? I'm the only person using this repo.
I tried using git rebase
, but that can either delete parts of a branch or move commits, but doesn't seem to be able to delete a single commit.
If I do git checkout <hash>
and then git reset --hard HEAD~1
I don't see the the commit anymore. Is it actually gone completely or is it still hidden in the repo?
Eventually it will be cleaned up by git, but you can look into git gc
to actually force a garbage collect.
The clean
command is different and won't take care of this for you.
这篇关于从git存储库中删除未提交的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!