Take the 2-minute tour ×  I added a file to the index with:  git
add somefile.txt  I then got the SHA1 for this file with:  git
hash-object somefile.txt  I now have a SHA1 and I would like to
retrieve the filename of the object in the index using the SHA1.
git show 5a5bf28dcd7944991944cc5076c7525439830122  This command
returns the file contents but not the name of the file.  How do
I get the full filename and path back from the SHA1?
share|improve this question add comment  4 Answers  up vote 8
down vote accepted  There's no such direct mapping in git as the
name of the file is part of the tree object that contains the
file, not of the blob object that is the file's contents.  It's
not a usual operation to want to retrieve a file name from a
SHA1 hash so perhaps you could expand on a real world use case
for it?  If you're looking at current files (i.e. the HEAD
commit) you can try the following.  git ls-tree -r HEAD | grep
<SHA1>  If you want to find the contents in previous commits
you'll need to do someth