Several "git add" before "git commit"
Here are my experiments.
git init
echo hello > some.txt
git add some.txt
-- objects
-- f2 (blob "hello")
echo hola > some.txt
git add some.txt
-- objects
-- f2 (blob "hello")
-- 53 (blob "hola")
git commit -m "..."
-- objects
-- f2 (blob "hello")
-- 53 (blob "hola")
-- 5c (tree
"some.txt" -> 53)
-- 61 (commit "tree 5c")
As we can see, each "git add" blob created and "git commit" committed the last blob 53.
But note that the intermediate blob "f2" is still in the repository. Is there a reason for this? How can I use this blob? Or how to remove it?
source to share
Saw me a minute to figure out what you were asking :)
Git stores everything for at least a period of time. If you run
git fsck
You should see
dangling blob f2...
It's a git construct to keep unobtrusive things sitting for a while. The idea is that if you "drunk" something, the file will still be found there. It is also a "lazy optimization" where adding something saves the state to commit as a content file, and compiling something is just referring to them. The cleaning part is separate. You should look at the documentation for Git pruning and Git gc .
By default, it will be cleared at some startup git gc
, which will occur after at least 2 weeks. In addition, the Git reflog utility (often used to salvage commits and redirects that screwed everything in) will be lost in the event of an aggressive cleanup.
source to share