经常 commit –amend,merge,rebase,reset –hard 后,会产生一些没有引用的 objects,这些有的可能会恢复你误操作后的修改,但是大部分时间是没用的。想着清理一下。
先查看有哪些
git fsck --full
Dangling blob = A change that made it to the staging area/index, but never got committed. One thing that is amazing with Git is that once it gets added to the staging area, you can always get it back because these blobs behave like commits in that they have a hash too!!
Dangling commit = A commit that isn’t directly linked to by any child commit, branch, tag or other reference. You can get these back too!
Dangling tree
然后查看已经没有的引用
git reflog expire --expire=now --all
git reflog: record when refs were update in the local repository, useful for recovering lost commits
清理
git gc --prune=now
git gc: clean up and optimize the local repository
参考:
http://www.tekkie.ro/news/howto-remove-all-dangling-commits-from-your-git-repository/
https://git-scm.com/docs/git-fsck
https://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery