How can I check a specific version of a single file in Git?

How can I check a specific version of a single file in git?

I found this mail on the mailing list that said:

$ git checkout HEAD~43 Makefile $ git reset Makefile 

But I don’t understand how to know β€œHEAD ~ 43” if I do git log aFile , how can I know which β€œHEAD-43” should I use?

And why do I need to run git reset for this file? What is he doing?

+74
git
Jul 23 '09 at 18:35
source share
3 answers

Do you know what to commit (i.e.: a specific revision) to which the file belongs? Then do:

 git checkout <commit> <file> 

Another team:

 git checkout HEAD~N <file> 

Goes when you want to get a version of a file from a range back (which I do for nostalgia).

+90
Jul 23 '09 at 18:39
source share

HEAD~43 is just rustic, so you can use a hash or tag. You need to separate the tree from the file name with -- , otherwise it will be considered the file name. For example.

 git checkout v0.45 -- filename git checkout HEAD^ -- filename git checkout 16bb1a4eeaa9 -- filename 
+15
Jul 23 '09 at 18:44
source share

HEAD~43 refers to committing (versioning) a file. Instead, you can use the commit hash code that you get from executing git log in the file. If you only need a file, you do not need to run git reset ; which is necessary only if you want to transfer the file to the current HEAD.

+2
Jul 23 '09 at 18:41
source share



All Articles