How can I check out a particular version of one file in Git?

How can I check out a particular version of one file in git?

I found this mail on the mailing list, which said:

  • Why does git rebase require a 3-way merge?
  • TFS 2013 in VS reports no history for a file with multiple commits in Git
  • Always push to different branch on remote, without setting upstream
  • Git check if there is outstanding commits to push
  • Error when using Git credential helper with gnome-keyring as Sudo
  • When open-sourcing a live Rails app, is it dangerous to leave the session key secret in source control?
  • $ git checkout HEAD~43 Makefile
    $ git reset Makefile
    

    But I don’t understand how to find out ‘HEAD~43’, if I do a git log aFile, how can I find out which ‘HEAD~43’ I should use?

    And why do I need to run git reset for that file? What does it do?

  • Using git with a proxy that rewrites SSL certificates
  • why some git commits are older than their parent?
  • Remove an Existing File from a Git Repo
  • Undoing a git pull --rebase
  • Share sub-project in git repository in another repo
  • git add . crashes and git commit -a crashes
  • 3 Solutions collect form web for “How can I check out a particular version of one file in Git?”

    You know what commit (ie: the specific revision) the file belongs to? Then do:

    git checkout <commit> <file>
    

    The other command:

    git checkout HEAD~N <file>
    

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

    HEAD~43 is just treeish, so you can use a hash or a tag. You have to separate treeish from the filename with --, otherwise it is treated as filename. For example.

    git checkout v0.45 -- filename
    git checkout HEAD^ -- filename
    git checkout 16bb1a4eeaa9 -- filename
    

    HEAD~43 refers to the commit (version) of the file. Instead of that, you can use the commit hash you get from doing git log on the file. If you just want the file, you don’t need to run git reset on it; that’s only necessary if you want to forward-port the file to the current HEAD.

    Git Baby is a git and github fan, let's start git clone.