Revert
Sometimes we end up making changes that need to be rolled back.
Git revert is a shorthand for undoing changes. It creates a new commit that undoes the changes from the previous commit.
Command
git revert <commit-ish>
Exercise: Revert a commit
- Navigate to the
learn-git
repository.- Revert the commit with log message
E
.- Check the logs to see the new revert commit.
Hint: Use
git log
to find the commit hash.
Solution: Revert a commit
Navigate to the learn-git
repository.
git revert 1fef21501625d1cb1ab99318ad0fa8487d6ef5cb
Note: We may get a revert conflict. Yes, we can get conflicts on reverts too. If so, resolve the conflict and commit the changes.
We can see the new commit in the logs.
git log --oneline --graph
Output
* d1a64a9 (HEAD -> main) Revert "E"