Bhanu Korthiwada

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

Many times we need to retrieve a single file from an older commit. The following command does that directly:

git checkout <commit_hash_value> <file_path_to_retrive>

You can also use HEAD references instead of a commit hash:

  • HEAD gets the file from the latest commit
  • HEAD^ gets the file from one commit before HEAD
  • HEAD^^ gets the file from two commits before HEAD
  • HEAD~10 gets the file from ten commits behind HEAD

Have a question or a different view? Email me.