Reputation: 11851
Is there a command that can take a ref and a file path, and output the full contents of the file as it was at that commit to STDOUT?
Eg. Something like this:
git show-me-the-file HEAD~2 some/file | do_something_with_piped_output_here
Upvotes: 50
Views: 16309
Reputation: 29473
git show <ref spec>:<path>
for example, if you want to see a file at commit point 9be20d1bf62 you do:
git show 9be20d1bf62:a/b/file.txt
if you want to see file on particular branch:
git show <branch name>:<path>
Upvotes: 16
Reputation: 84343
You want git show
or git archive
for this use case. The git-show command is more oriented towards sending files to standard output, though.
# Show .gitignore from revision before this one.
git show HEAD^:.gitignore
The part before the colon is a tree-ish formed according to gitrevisions(7), while the latter half is a path relative to the top of your git working tree.
Upvotes: 5