According to an answer of “How often should you use git-gc?”, git gc
is run automatically every time you push to remote.
I commented on the answer but never got a response, so I’m asking here.
I have unreachable commits in my tree (as a result of
git commit --amend
). This can be verified withgit log --reflog
. I pushed a branch to the remote repository and checked my tree again; the unreachable commits were still there. Apparentlygit gc
was not run when this push happened. … ?
Example:
$ git commit -m 'commit A'
$ git commit -m 'commit B'
$ git commit -m 'commit C'
$ git commit --amend -m 'commit D'
$ git commit -m 'commit E'
$ git commit -m 'commit F'
$ git push origin master
$ git log --reflog
* commit F (HEAD -> master, origin/master)
* commit E
* commit D (an amendment of C)
|
| * commit C
|/
* commit B
* commit A
When I push master to remote and run git log --reflog
, commit C is still visible. This is still the case even if commit C is over 30 days old. I thought git push
automatically runs git gc
, and I thought git gc
deletes the unreachable commits (in this case, C). Am I missing something?