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:

  • How to retrieve a single file from specific revision in Git?
  • How to get just one file from another branch

UPDATE 2015-01-19:

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)