Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To complete your own answer, the syntax is indeed</p> <pre><code>git show object git show $REV:$FILE git show somebranch:from/the/root/myfile.txt git show HEAD^^^:test/test.py </code></pre> <p>The command takes the usual style of revision, meaning you can use any of the following:</p> <ol> <li>branch name (as <a href="https://stackoverflow.com/review/suggested-edits/3041393">suggested</a> by <a href="https://stackoverflow.com/users/17708/ash">ash</a>)</li> <li><code>HEAD</code> + x number of <code>^</code> characters</li> <li>The SHA1 hash of a given revision</li> <li>The first few (maybe 5) characters of a given SHA1 hash</li> </ol> <p><strong>Tip</strong> It's important to remember that when using "<code>git show</code>", <strong>always specify a path from the root of the repository</strong>, not your current directory position. </p> <p>(Although <a href="https://stackoverflow.com/users/179675/mike-morearty">Mike Morearty</a> mentions that, at least with git 1.7.5.4, you can specify a relative path by putting "<code>./</code>" at the beginning of the path -- for example:</p> <pre><code>git show HEAD^^:./test.py </code></pre> <p>)</p> <hr> <p>Before git1.5.x, that was done with some plumbing:</p> <p><code>git ls-tree &lt;rev&gt;</code><br> show a list of one or more 'blob' objects within a commit</p> <p><code>git cat-file blob &lt;file-SHA1&gt;</code><br> 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 </p> <pre><code>git cat-file -p $(git-ls-tree $REV $file | cut -d " " -f 3 | cut -f 1):: </code></pre> <p>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.</p> <hr> <p>Note: since Git 2.11 (Q4 2016), you can apply a content filter to the <code>git cat-file</code> output!</p> <p>See <a href="https://github.com/git/git/commit/321459439e19517c412cab1cfbb64a2749f272c9" rel="noreferrer">commit 3214594</a>, <a href="https://github.com/git/git/commit/7bcf341453572a227036afec76bdab451b798870" rel="noreferrer">commit 7bcf341</a> (09 Sep 2016), <a href="https://github.com/git/git/commit/7bcf341453572a227036afec76bdab451b798870" rel="noreferrer">commit 7bcf341</a> (09 Sep 2016), and <a href="https://github.com/git/git/commit/b9e62f60115c75c5be5de593862925c8b8d7e683" rel="noreferrer">commit b9e62f6</a>, <a href="https://github.com/git/git/commit/16dcc2992b80d30f99c41fd7cc858e9d1c9dbca3" rel="noreferrer">commit 16dcc29</a> (24 Aug 2016) by <a href="https://github.com/dscho" rel="noreferrer">Johannes Schindelin (<code>dscho</code>)</a>.<br> <sup>(Merged by <a href="https://github.com/gitster" rel="noreferrer">Junio C Hamano -- <code>gitster</code> --</a> in <a href="https://github.com/git/git/commit/7889ed25ac709624446b0b4d887dd3633e81f44a" rel="noreferrer">commit 7889ed2</a>, 21 Sep 2016)</sup> </p> <blockquote> <h2><code>cat-file</code>: support <code>--textconv</code>/<code>--filters</code> in batch mode</h2> <p>Even though "<a href="https://git-scm.com/docs/git-hash-object" rel="noreferrer"><code>git hash-objects</code></a>", 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 "<a href="https://git-scm.com/docs/git-cat-file" rel="noreferrer"><code>git cat-file</code></a>", 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"</p> </blockquote> <pre><code>git config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m &lt;" git cat-file --textconv --batch </code></pre> <p>Note: "<code>git cat-file --textconv</code>" started segfaulting recently (2017), which has been corrected in Git 2.15 (Q4 2017)</p> <p>See <a href="https://github.com/git/git/commit/cc0ea7c9e5c3d3bf9623415737b595c9d26b9b6d" rel="noreferrer">commit cc0ea7c</a> (21 Sep 2017) by <a href="https://github.com/peff" rel="noreferrer">Jeff King (<code>peff</code>)</a>.<br> <sup>(Merged by <a href="https://github.com/gitster" rel="noreferrer">Junio C Hamano -- <code>gitster</code> --</a> in <a href="https://github.com/git/git/commit/bfbc2fccfdff0fe189337de67e16fc132b8ee2a5" rel="noreferrer">commit bfbc2fc</a>, 28 Sep 2017)</sup> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload