Git retrieve a single file from old commit

Many times we wanted to retrieve a single file from old commit, below is the simple command to get the job done.

git checkout <commit_hash_value> <file_path_to_retrive>

We can also use HEAD reference in place of hash value:

  • HEAD  will get file from last commit
  • HEAD^ : Last Commit - 1
  • HEAD^^ : Last Commit - 2
  • HEAD~10 : 10 Commits behind the git HEAD