如何在git中硬删除孤立提交? [英] How to hard delete an orphan commit in git?

查看:150
本文介绍了如何在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

这篇关于如何在git中硬删除孤立提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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