I have a Git repository and I'd like to see how some file looked a few months ago. I found the revision at that date, it's:
git-show 27cf8e84bb88e24ae4b4b3df2b77aab91a3735d8 my_file.txt
To complete your own answer, the syntax is indeed
git show object git show $REV:$FILE git show somebranch:from/the/root/myfile.txt git show HEAD^^^:test/test.py
The command takes the usual style of revision, meaning you can use any of the following:
HEAD+ x number of
Tip It's important to remember that when using "
git show", always specify a path from the root of the repository, not your current directory position.
(Although Mike Morearty mentions that, at least with git 18.104.22.168, you can specify a relative path by putting "
./" at the beginning of the path -- for example:
git show HEAD^^:./test.py
Before git1.5.x, that was done with some plumbing:
git ls-tree <rev>
show a list of one or more 'blob' objects within a commit
git cat-file blob <file-SHA1>
cat a file as it has been committed within a specific revision (similar to svn cat). use git ls-tree to retrieve the value of a given file-sha1
git cat-file -p $(git-ls-tree $REV $file | cut -d " " -f 3 | cut -f 1)::
git-ls-tree lists the object ID for $file in revision $REV, this is cut out of the output and used as an argument to git-cat-file, which should really be called git-cat-object, and simply dumps that object to stdout.
Note: since Git 2.11 (Q4 2016), you can apply a content filter to the
git cat-file output!
See commit 3214594, commit 7bcf341 (09 Sep 2016), commit 7bcf341 (09 Sep 2016), and commit b9e62f6, commit 16dcc29 (24 Aug 2016) by Johannes Schindelin (
(Merged by Junio C Hamano --
gitster -- in commit 7889ed2, 21 Sep 2016)
--filtersin batch mode
Even though "
git hash-objects", which is a tool to take an on-filesystem data stream and put it into the Git object store, allowed to perform the "outside-world-to-Git" conversions (e.g. end-of-line conversions and application of the clean-filter), and it had the feature on by default from very early days, its reverse operation "
git cat-file", which takes an object from the Git object store and externalize for the consumption by the outside world, lacked an equivalent mechanism to run the "Git-to-outside-world"
git config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m <" git cat-file --textconv --batch