View a file in a different Git branch without changing branches

This should work:

git show branch:file

Where branch can be any ref (branch, tag, HEAD, …) and file is the full path of the file. To export it you could use

git show branch:file > exported_file

You should also look at VonC‘s answers to some related questions:

UPDATE 2015-01-19:

Nowadays you can use relative paths with git show a1b35:./file.txt.

Leave a Comment