列出和删除没有分支的 Git 提交(悬空?) [英] Listing and deleting Git commits that are under no branch (dangling?)

查看:38
本文介绍了列出和删除没有分支的 Git 提交(悬空?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Git 存储库,其中包含大量不在特定分支下的提交,我可以git show 它们,但是当我尝试列出包含它们的分支时,它什么都不报告.

I've got a Git repository with plenty of commits that are under no particular branch, I can git show them, but when I try to list branches that contain them, it reports back nothing.

我认为这是悬空提交/树问题(由于 -D 分支),所以我修剪了 repo,但在那之后我仍然看到相同的行为:

I thought this is the dangling commits/tree issue (as a result of -D branch), so I pruned the repo, but I still see the same behavior after that:

$ git fetch origin

$ git fsck --unreachable
$ git fsck

没有输出,没有悬空(对吧?).但是提交存在

No output, nothing dangling (right?). But the commit exists

$ git show 793db7f272ba4bbdd1e32f14410a52a412667042
commit 793db7f272ba4bbdd1e32f14410a52a412667042
Author: ...

并且它无法通过任何分支访问

and it is not reachable through any branch as

$ git branch --contains 793db7f272ba4bbdd1e32f14410a52a412667042

没有输出.

那个提交的状态到底是什么?如何列出处于类似状态的所有提交?如何删除这样的提交?

What exactly is the state of that commit? How can I list all commits in a similar state? How can I delete commits like those?

推荐答案

没有输出,没有悬空(对吧?)

No output, nothing dangling (right?)

请注意,从您的 reflog 中引用的提交被认为是可访问的.

Note that commits referred to from your reflog are considered reachable.

那个提交的状态到底是什么?如何列出所有具有相似状态的提交

What exactly is the state of that commit? How can I list all commits with similar state

通过 --no-reflogs 说服 git fsck 向你展示它们.

Pass --no-reflogs to convince git fsck to show them to you.

如何删除这样的提交?

一旦您的 reflog 条目过期,这些对象也将被 git gc 清理.

Once your reflog entries are expired, those objects will then also be cleaned up by git gc.

到期由 gc.pruneexpiregc.reflogexpiregc.reflogexpireunreachable 设置调节.参见git 帮助配置.

Expiry is regulated by the gc.pruneexpire, gc.reflogexpire, and gc.reflogexpireunreachable settings. Cf. git help config.

默认值都很合理.

这篇关于列出和删除没有分支的 Git 提交(悬空?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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