Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search for string in dangling commits in Git

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.

like image 443
chx Avatar asked Feb 20 '14 09:02

chx


People also ask

How do you see dangling commits?

We can use the git reflog to recover a branch (of dangling commits) which was deleted without merging it. We can recover deleted commits only if it is present in local object store. If it was garbage collected, then we can't recover it.

How do I search for a specific commit in git log?

Looking up changes for a specific commit If you have the hash for a commit, you can use the git show command to display the changes for that single commit. The output is identical to each individual commit when using git log -p .

Can you grep git log?

Lucky for you, git has a 'grep' mode that's perfect for doing a git log search! and you'll see all of the log messages which contain the our search term!

Can we search for a commit in GitHub?

On GitHub, you can see the commit history of a repository by: Navigating directly to the commits page of a repository. Clicking on a file, then clicking History, to get to the commit history for a specific file.


1 Answers

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

like image 179
mockinterface Avatar answered Oct 12 '22 23:10

mockinterface