22 / 01 / 19

如何处理 git dangling commit 的问题

这是一篇自用快速操作指南,非技术研究。

在执行 git rebase 的时候,突然出现了以下错误。

Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
error: The last gc run reported the following. Please corrent the root cause and remove .git/gc.log.
Automatic cleanup will not be performed until the file is removed.

warning: There are too many unreachable loose objects; run 'git prune' to remove them.

查了一下,发现是有大量的 dangling commit 导致出现了这个提示,会阻碍执行 git rebase 等操作,于是执行下面两个命令将这些无用的 dangling commit 删除即可。

git reflog expire --expire=now --all git gc --prune=now

提示

  • git commit --amend 会生成 dangling commit。
  • 大量的 dangling commit 会影响 git 的”性能“。例如执行 git push 会卡住等。也可以试试这个办法,清掉 dangling commit 之后就秒 push 了。
  • 通过 git fsck --lost-found 命令查看 dangling commit 列表。
Powered by Gridea