如何真正删除一个git分支(即删除所有对象/提交)? [英] How to REALLY delete a git branch (i.e. remove all of its objects/commits)?

查看:158
本文介绍了如何真正删除一个git分支(即删除所有对象/提交)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git树,像

                 A---B---C topic
                /
           D---E---F---G master     <--

I想要移除主题及其上的所有对象。

I would like to remove topic and all objects on it.

我注意到了主题的SHA ID,然后输入:

I note the SHA ID of topic, then type:

git branch -D topic
git gc                                   #  <-- I also tried prune here...
git checkout -b temp <SHA1 ID of topic>

在最后一个命令后,我希望得到一个错误(类似不存在的对象ID .. 。或者像这样)。然而,没有错误,并且gitk显示了与上面相同的树结构??

After the last command I expect to get an error (something like "Non-existent object ID..." or somth. like that). However there is no error and gitk shows the same tree structure as above??

我错过了什么 - 我认为gc / prune应该删除所有不可访问的对象?

What am I missing - I thought gc/prune are supposed to delete all unreachable objects?

推荐答案

只要gc修剪通常不足以摆脱回购中的额外对象。如果提交仍然在reflog中引用,那么它将不会考虑那些不可到达的对象,因此可能无法进行修剪。

Just the gc prune is often not enough to get rid of the extra objects in the repo. If commits are still referenced in the reflog, it won't consider those objects unreachable and hence ripe for pruning.

以下是我的工作:

git reflog expire --expire=now --all
git gc --aggressive --prune=now
git repack -a -d -l

这会对您的回购协议的历史进行一些更改,并且如果其他人依赖于您的回购分支,可能会出现问题。

This will make some changes to your repo's history, and may well present difficulties if others are depending on the branches you blow away.

您可能需要重新克隆存储库才能看到其大小的差异。

You may have to re-clone your repository to actually see a difference in its size.

这篇关于如何真正删除一个git分支(即删除所有对象/提交)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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