Joel
Joel

Reputation: 11851

Git: whole file to stdout

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

Answers (3)

eqzx
eqzx

Reputation: 5579

git show

e.g.

git show HEAD:./<path_to_file>

Upvotes: 68

Op De Cirkel
Op De Cirkel

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

Todd A. Jacobs
Todd A. Jacobs

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

Related Questions