Last Updated: December 29, 2022
·
298.4K
· dsci

Git: checkout a single file from a specific commit

Sometimes we mess around with a file and than there is a desire to have a particular state of this file back to the workspace.

That's pretty easy in Git and well discussed on the internets. However, maybe as a personal reminder, it can be achieved like the following:

git checkout <COMMIT#> <path/to/the/messed/up/file>

Example:

git checkout f08a63ff4fa7b8479f8c698e5998ee1afcac3a4e Gemfile

2 Responses
Add your response

In addition, adding the -p option allows you to interactively apply a patch of the file if you only need a subset of the file contents.

over 1 year ago ·

Thanks for the great advice

over 1 year ago ·