Git Revert
git revert
is useful when you want to undo the changes made by a specific commit without rewriting history
git revert <commit-hash>
if the git log looks like
* f6a4e5b Fixed a bug in the new feature
* d4c1b2a Added new functionality
* a2b3c4d Initial commit
and the following git command is used
git revert d4c1b2a
Git will open a text editor to enter a commit message for the revert commit. It usually pre-populates the message with something like “Revert ‘Added new functionality”. Modify this message if needed, save, and exit the editor.
If there are no conflicts, Git will automatically create a new commit that reverts the changes introduced by commit d4c1b2a. Commit history will now include the revert commit:
* 2468abc (HEAD -> main) Revert "Added new functionality for user registration"
* f6a4e5b Fixed a bug in the new feature
* d4c1b2a Added new functionality
* a2b3c4d Initial commit