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.

  • To get Git-prompt work in Zsh without a bug in a function
  • Merge svn branch to new git branch
  • How to deal with file names which contain spaces in Ruby(In Git Bash)
  • Git library for Ruby or Python?
  • Restoring a file from Git?
  • Git seems stuck on my old account
  • Heroku is not updating my code?
  • Git Diff and Meld on Windows
  • How to call git commands on private repo using cygwin to execute bash script in Jenkins
  • Xcode: remove working copy
  • How to deploy code from localhost to docker containers using Git?
  • Is there a preferred path where I should initialise my Git repo on Mac OS X?
  • One Solution collect form web for “Search for string in dangling commits in Git”

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

    Git Baby is a git and github fan, let's start git clone.