Git for Windows: get older verisons of file?
I am using the great Git for Windows and I want to get old versions of a file. I mean that I want to get the entire file and not just view the code in a preview.
2 Solutions collect form web for “Git for Windows: get older verisons of file?”
The easiest way to do that is to just checkout a revision by hash of the file that you want, or the change and go back one.
gitk to find the hash of the commit that you are interested in.
You can then use
git checkout hashhere. This will set your whole repository back to that hash.
If all you want is a specific file, use
git checkout hash filepath.
git checkout 4fda14eefe0388e836aac8feaca68ab18bfad6b1 path/to/file.c
If all you want to do is see a file and save it off to somewhere else,
git show is capable of doing that,
git show hash:filepath and pipe it out to somewhere you want to save it:
git show 4fda14eefe0388e836aac8feaca68ab18bfad6b1:path/to/file.c > savetohere.txt
You can also use tree-ish to specify the number of revisions to go back, as well:
git show master~2:path/to/file.c > savetohere.txt
Which basically says, “2 revisions ago on the master branch, show the path/to/file.c file and pipe the results to savetohere.txt.”
git checkout <tree-ish> <path>
git checkout master~2 Makefile
Reference: git checkout man page.