3

I have made some test commits (to test a commit hook) and always reset the index to my last normal commit. Now these stale commits still exist:

> git reflog
fcdabf7 HEAD@{0}: reset: moving to fcdabf7e01845d6f000fc3cef2edc999c57a7e29
5c97564 HEAD@{1}: commit: t
fcdabf7 HEAD@{2}: reset: moving to fcdabf7e01845d6f000fc3cef2edc999c57a7e29
ae52246 HEAD@{3}: commit: t
fcdabf7 HEAD@{4}: reset: moving to fcdabf7e01845d6f000fc3cef2edc999c57a7e29
c58aeef HEAD@{5}: commit: t
fcdabf7 HEAD@{6}: reset: moving to fcdabf7e01845d6f000fc3cef2edc999c57a7e29
3a2cc3b HEAD@{7}: commit: test

How can I remove them? And for technical understanding: If I leave them alone, will they be pushed to the upstream repo if I do a push?

AndiDog
  • 68,631
  • 21
  • 159
  • 205
  • 2
    Afaik you will only push the commits that are reachable through the branch you push. If it is not in `git log`, it's not pushed. Also try `git gc` to clear unreachable commits. – ZeissS Oct 14 '12 at 13:05
  • I tried `git gc --aggressive --prune=2015-01-01` but that didn't remove them from reflog. – AndiDog Oct 14 '12 at 14:08
  • see http://stackoverflow.com/q/1904860/11343 – CharlesB Oct 14 '12 at 14:26

2 Answers2

1

First of all, you need not worry about the dangling commits making their way into a remote repository. They will not be pushed, and will generally be cleaned up in due course.

However, if you want to clear off such dangling object, try running:

git gc --prune=now
manojlds
  • 290,304
  • 63
  • 469
  • 417
1

Commits referenced by the reflog entries are not dangling per se. To clear the reflog,

git reflog expire --expire=0 --all

afterwards which git prune can be used to remove the - now-dangling - commits.

jørgensen
  • 10,149
  • 2
  • 20
  • 27
  • That works and `git gc --aggressive --prune=now` removed the commits. Of course that means I lose the reflog everytime I do this. – AndiDog Oct 14 '12 at 16:27