code_junkie

Git - finding a filename from a SHA1

Nov 13th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. git add somefile.txt
  2.  
  3. git hash-object somefile.txt
  4.  
  5. git show 5a5bf28dcd7944991944cc5076c7525439830122
  6.  
  7. git ls-tree -r HEAD | grep <SHA1>
  8.  
  9. git rev-list <commit-list> | xargs -n1 -iX sh -c "git ls-tree -r X | grep <SHA1> && echo X"
  10.  
  11. git ls-tree <commit-sha1>
  12.  
  13. #!/bin/sh
  14.  
  15. obj_hash=$1
  16.  
  17. # go over all trees
  18. git log --pretty=format:'%T %h %s'
  19. | while read tree commit subject ; do
  20. git ls-tree -r $tree | grep "$obj_hash"
  21. | while read a b hash filename ; do
  22. if [ "$hash" == "$obj_hash" ]; then
  23. f=$filename
  24. echo $f
  25. break
  26. fi
  27. if $f ; then break; fi
  28. done
  29. if $f; then break; fi
  30. done
Add Comment
Please, Sign In to add comment