Step by step how to revert a file from a commit:
- Navigate to the repo which has the file version you are looking for
- Click through until you get to the file in question
- Top right of the table you will see the last commit with a commit ID, 7 characters long and cryptic looking
- Copy that number (example:
491ce18) and remember the
- In your terminal (I like to do this in VSC in the project I’m in), use the following command
git checkout 491ce18 -- /path/to/my/file.php
- You should now have some changes to stage and commit, these are the revert of the file you picked to the commit you specified
- Now check those changes in with
git commit -m "Revert of file.php"
- You’re all done.
Things to note:
If you’re like me, you only half pay attention most of the time or are going too fast for your own good. It’s ok, it happens to the best of us.
Make sure you don’t grab the commit ID of the commit you need to revert, I’ve done this and it results in several revert commits and mass confusion. Plus you look like an idiot, so that’s not helpful at all.
I’m a big fan of GUI for git but have struggled with this exact operation in most clients, so you may want to get comfortable with command line for stuff like this. I fought it for years but it gets easier by just doing it. I promise.