Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: whole file to stdout

Tags:

git

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 
like image 565
Joel Avatar asked Jun 13 '12 02:06

Joel


People also ask

How do I see the contents of a file in Git?

The Git Show command allows us to view files as they existed in a previous state. The version can be a commit ID, tag, or even a branch name. The file must be the path to a file. For example, the following would output a contents of a file named internal/example/module.go file from a tagged commit called “release-23”.

What does cat do in git?

DESCRIPTION. In its first form, the command provides the content or the type of an object in the repository. The type is required unless -t or -p is used to find the object type, or -s is used to find the object size, or --textconv or --filters is used (which imply type "blob").


2 Answers

git show

e.g.

git show HEAD:./<path_to_file>

like image 126
eqzx Avatar answered Sep 22 '22 21:09

eqzx


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>

like image 24
Op De Cirkel Avatar answered Sep 21 '22 21:09

Op De Cirkel