Git: Revert A Single File From A Commit

First, find the commit and the path to the file.

Then run the following.

git checkout <commit sha> -- path/to/the/file.txt

If the file has been deleted then you'll need to look at the parent commit of the commit you want. This is done with "~1".

git checkout <commit sha>~1 -- path/to/the/file.txt

Then, commit the changes.

git commit -m "Reverting path/to/the/file.txt changes."

An alternative method is to use "git apply".

git show <commit sha> -- path/to/the/file.txt | git apply -R

You will still need to commit the changes after this patch has been applied.

Add new comment

The content of this field is kept private and will not be shown publicly.
7 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.