Spotlight
After the Circus

Random Sample
Chateau Laurier at Sunset








contact me
jean at geemoo dot ca
Blog

Feb 10, 2009
For some reason, I always have trouble remembering how to get a file from my git history, so I'm gonna make a note of it here.

The command to make this work is git show <TREE-ISH>:path/to/file. This will output the contents of the file.
For some reason, I also keep thinking that this will include the diff info as well, but it does not. It's just the contents of the file. <TREE-ISH> can be a SHA1, HEAD, HEAD~10 or whatever you like.

At this point, you can redirect it into the original file to replace it's contents, view it in your editor, or whatever you like.

Note: I also had it mentioned to me by Bart, that if I just wanted to replace the file, I could just use git checkout <TREE-ISH> -- file.

Update: I just ran into a bit of a gotcha. When you specify the file that you wish to show, you must specify the full relative path from the root of the repo, even if you are in the current directory of the file you wish to see. For example, if you have a repo that is in /home/foo, and in the repo you have a file called bar/buzz, you must use git show HEAD:bar/buzz, even if you are currently in bar/.
Tags: git, linux