Git: what is a dangling commit/blob and where do they come from?

被刻印的时光 ゝ 提交于 2019-11-27 06:25:54

During the course of working with your git repository, you may end up backing out of operations, and making other moves that cause intermediary blobs, and even some things that git does for you to help avoid loss of information.

Eventually (conditionally, according to the git gc man page) it will perform garbage collection and clean these things up. You can also force it by invoking the garbage collection process, git gc.

For more information about this, see Maintenance and Data Recover on the git-scm site.

A manual run of GC will by default leave 2 weeks prior to the runtime of this command of a safety net. It is in fact encouraged to run the GC occasionally to help ensure performant use of your git repository. Like anything, though, you should understand what it is doing before destroying those things that may be important to you.

Elijah Lynn

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!

HOWTO remove all dangling commits from your git repository from http://www.tekkie.ro/news/howto-remove-all-dangling-commits-from-your-git-repository/

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

Make sure you really want to remove them, as you might decide you need them after all.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!