Philipp Hoffmann

notes to myself

How to view any Git repository file without checking it out

Here is how to have a quick look into any file in your git repository without checking it out or overwriting your working copy.

git show master:path/to/file/file.xml

This will show file.xml of the master branch. Git will echo the contents of the file to the standard output. So to actually save a temporary copy of the file for inspection you can just redirect the output into a new file:

git show test:path/to/file/file.xml > temp_file.xml

or pipe it into your favorite editor like this

git show test:path/to/file/file.xml | vim -

You can even look into files in the origin repository:

git show origin:path/to/file/file.xml

There is a lot more you can do with git show like showing diffs. Check out git help show for more information.