12

The following monstrosity very nicely found a git stash containing the word Upload which is what I was looking for:

git fsck --no-reflog | awk '/dangling commit/ {print $3}' | \
while read ref; do if [ "`git show -p $ref|grep -c Upload`" -ne 0 ]; then echo $ref ; fi ; done 

Is there a prettier version of this? I guess the pickaxe should work but git log -g doesn't see this commit.

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
chx
  • 11,270
  • 7
  • 55
  • 129

1 Answers1

5

... but git log -g doesn't see this commit

Commits that are (still) referenced by the reflog are considered reachable and not dangling. Thus running git log –g is contrary to what you wanted, so no surprises here.

Commits will be reachable via reflog for the gc.reflogExpire timespan, with a default of 90 days.

Is there a prettier version of this?

No, git fsck is the right way for accessing dangling commits.

mockinterface
  • 14,452
  • 5
  • 28
  • 49
  • OK, so `git fsck` is the right way for the first half. Then, given a list of commits, is there a better way to search in them? – chx Feb 22 '14 at 02:54
  • @chx I don't believe so, since the commits are dangling. You cannot rely on git walking any trees rooted in those commits for your stead with something like `git log --grep=Upload`, and thus have to process each commit individually yourself. – mockinterface Feb 22 '14 at 03:01
  • 1
    I ended up doing this: `git fsck --no-reflog | awk '/dangling commit/ {print $3}' | xargs -n1 git log -p -1 > commits.txt ` To at least get a single file of all the code contained in the dangling commits. – Mat Schaffer Dec 21 '15 at 02:35