Git and GitHub: How to Revert a Single File

Jorge Freitas
Apr 21, 2021

After commit your changes to the Pull Request, something could be necessary to revert a single file from your commit. Doing a new commit can lead to a messy commit history. Reverting the file is a much cleaner.

Find commit ID

git log <path to file>

Select the previous commit

git checkout <commit id> -- <path to file>

Push to server

git add .
git commit -m “revert package-lock.json”
git push

And that’s pretty much it, in this way you reverted a file keeping a clean git history.

--

--