Search for string in dangling commits in Git
Asked Answered
C

1

14

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.

Centuple answered 20/2, 2014 at 9:47 Comment(2)
Did you try git log -g -p?Tetrabasic
Sure, it doesn't work -- again, git log -g doesn't list the 'winning' commit.Centuple
F
6

... 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.

Fluorine answered 21/2, 2014 at 23:47 Comment(3)
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?Centuple
@Centuple 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.Fluorine
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.Strum

© 2022 - 2024 — McMap. All rights reserved.