Suppose we have branch:
A <-- B <-- C
Suppose further we use git commit --amend to change C into C':
A <-- B <-- C'
Question: What happens to C (literally speaking)? Does that commit still exist somewhere in git's object store (it's just dangling from our master branch)?
Yes, it exists and if you know its sha, you can do
git show <SHA>
to see it.
It simply remains "orphan" and it's eventually pruned by the garbage collector.
The final situation would be
A -- B -- C'
\
\-- C (this commit is unreachable, so it's not shown in normal git logs)
About the garbage collector, aka git gc
Runs a number of housekeeping tasks within the current repository, such as compressing file revisions (to reduce disk space and increase performance) and removing unreachable objects which may have been created from prior invocations of git add.
Users are encouraged to run this task on a regular basis within each repository to maintain good disk space utilization and good operating performance.
Some git commands may automatically run git gc; see the --auto flag below for details. If you know what you’re doing and all you want is to disable this behavior permanently without further considerations, just do:
git config --global gc.auto 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With