Revert a Single File in Git

Revert a single file to its previous status.

the file isn’t committed yet:

git checkout filename

the file is already committed:

filename is the path to the target file, hash is the hash of the commit you want to switch to.

git checkout hash filename

# or

git reset hash filename

If there are changes across several commits to a file we can use a branch too instead of a hash:

git checkout master -- filename
Spread the word on BlueskyEdit on GithubPublished on Jan 24, 2020

Copyright © 2019...2025 Nick Plekhanov