R's Workshop

Git: Retrieve Specific Version of File

This post describes how to retrieve a specific version of a file from Git.

Retrieve Specific Version of a File

Using Git Checkout

# TREE-ISH could be a commit/tag/branch
# '--' indicates not interpret any more arguments as options
$ git checkout TREE-ISH -- /PATH/TO/FILE

Using Git Restore (for Git 2.23+)

# TREE-ISH could be a commit/tag/branch
# '--' indicates not interpret any more arguments as options
$ git restore -s TREE-ISH -- /PATH/TO/FILE

# Restore working tree and staging area
$ git restore -s TREE-ISH -SW -- /PATH/TO/FILE

Reference

Gerrit Git