I changed an image file in git and it was 2 commits ago. How do I go back to 2 previous commits ago?
What is the easiest method of doing this file revert via the command line with the least amount of commands required?
In case you are using the Tower Git client, you can use the reset command right from a commit's contextual menu. And in case you made a mistake: simply hit CMD+Z to undo the reset and restore the removed commits!
The syntax of the command is git revert --no-commit <commit> . Thus, to revert the three commits of the bug fixes done, we need to do as follows. Thus, the repository in Git is now in the state before committing the bug1 fixed . We have used the sha1 name of the commits to revert each commit.
Tip: When you revert multiple commits, it's best to revert in order from newest to oldest. If you revert commits in a different order, you may see merge conflicts. Click History. Right-click the commit you want to revert and click Revert Changes in Commit.
Just check out the old version of that file:
git checkout HEAD~2 -- path/to/file
Or more explicit:
git checkout commit-id -- path/to/file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With