如何在git中硬删除孤立提交?
我有本地提交不在任何我想删除的分支上。
我不想重定义它们,我真的想要删除它们,并且释放与这些提交相关的所有内容。
I have local commit that are not on any branch that I would like to delete. I don't want to rebase them, I really want to delete them, and loose all the content related to these commit.
是他们的命令这样做吗?
Is their a command to do so ?
到目前为止,我已经尝试过许多人提出的交互式重新分配,但它只是提交,不会删除它们。我也尝试过使用reflog delete,但我无法弄清楚如何将特定的提交ID传递给命令。
So far I've tried interactive rebase as many suggested, but it just move commit around, it doesn't delete them. I've also tried to use reflog delete, but I can't figure out how to pass a specific commit Id to the command.
这里是工作树:
o [master] Commit #6
|
o Commit #5
|
| o Commit #4
|/
o Commit #3
|
o Commit #2
|
o Commit #1
我想物理删除提交#4。
I want to physically delete the commit #4.
如果commit没有被任何东西引用,它会被git的垃圾回收和时删除。
If the commit is not referenced by anything, it will be removed with git's garbage collection, in time.
如果您想事先强制执行,请使用 git gc --prune = now --aggressive
If you want to force it before hand, use git gc --prune=now --aggressive