2

Per http://snipplr.com/view/11513/, I tried

$ git reflog expire --expire=1.minute refs/heads/master
$ git fsck --unreachable # now I see those tarball blobs!
$ git prune # hasta la vista, baby
$ git gc # cleanup and repack the repo

but it did not help, I am still able to checkout by a hash code.

Phil Miller
  • 36,389
  • 13
  • 67
  • 90
sanyo
  • 21
  • 1
  • 1
    Note that unless the discarded commits take a significant amount of disk space or are a security risk, you can just ignore this, and it'll take care of itself eventually. – Cascabel Mar 14 '12 at 06:35

2 Answers2

3

The commands you linked to didn't work because git gc doesn't prune anything less than two weeks old by default, so you need to specify that you want to prune everything:

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

The call to git prune is redundant, since git gc calls it anyway. The call to git fsck is only for display purposes and need not be run.

Note that these commands will make it impossible to recover any other unreachable commits, and of course the reflog will be cleared making any of its nice rollback features unusable for past history.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
  • git reflog --expire-unreachable=now fatal: unrecognized argument: --expire-unreachable=now correct syntax seems to be: git reflog expire --expire-unreachable=now Unfortunately after gc I am still able to checkout by a hash code – sanyo Mar 14 '12 at 05:52
  • Yup, you're right, I've updated. Do the commit hashes in question show up in `git fsck --unreachable`? – Andrew Marshall Mar 14 '12 at 06:11
  • Make sure you don't have reference to that commit `git tag --contains ` and `git branch -a --contains ` and then repack them. – J-16 SDiZ Mar 14 '12 at 07:30
  • you might want to to add the `--rewrite` option to `git reflog expire`, see http://stackoverflow.com/questions/9184344/git-reflog-expire-and-git-fsck-unreachable for more information on expiring stuff from the reflog – Geoffrey Bachelet Mar 14 '12 at 10:59
0

Among other things, you'd need to also expire HEAD's reflog in order for the commit to become dereferenced.

Amber
  • 507,862
  • 82
  • 626
  • 550
  • Can you please explain how to expire the HEAD's reflog? Is it: git reflog expire --expire-unreachable=now – sanyo Mar 14 '12 at 05:58
  • It'd be the same as the command for `refs/heads/master`, except using `HEAD` instead. – Amber Mar 14 '12 at 06:43