I have a project with a lot of subdirs, and somewhere in there in some deep subdir there was a file called foo.py. Couple years ago it was deleted, the delete was committed and pushed. How can I see the contents of foo.py as it existed right before the deletion?
Asked
Active
Viewed 188 times
1 Answers
1
If you know the full path to the file, you can use git log
to find the last commit in which it existed:
git log -1 -- path/to/foo.py
This will return something like:
commit 6b6df3bf2aed05b4ed63a9c99a1e61c7b3059aa6
Author: you
Date: Thu Jul 2 17:56:30 2015 +0900
Delete foo.py
You could then...
...check out the parent of that commit and inspect the file:
git checkout 6b6df3bf2aed05b4ed63a9c99a1e61c7b3059aa6^
cat path/to/foo.py
...or use git show
to display it on stdout:
git show 6b6df3bf2aed05b4ed63a9c99a1e61c7b3059aa6^:path/to/foo.py

larsks
- 277,717
- 41
- 399
- 399