You can see dangling commits with git log -g
.
-g, --walk-reflogs
Instead of walking the commit ancestry chain, walk reflog entries from
the most recent one to older ones.
So you could do this to find a particular string in a commit message that is dangling:
git log -g --grep=search_for_this
Alternatively, if you want to search the changes for a particular string, you could use the pickaxe search option, "-S":
git log -g -Ssearch_for_this
# this also works but may be slower, it only shows text-added results
git grep search_for_this $(git log -g --pretty=format:%h)
Finally, you could use gitk to visualise the dangling commits with:
gitk --all $(git log -g --pretty=format:%h)
And then use its search features to look for the misplaced file. All these work assuming the missing commit has not "expired" and been garbage collected, which may happen if it is dangling for 30 days and you expire reflogs or run a command that expires them.