To revert a Git commit, you can use the git revert command followed by the commit hash you want to undo. Here’s the format:
git revert <commit_hash>
Steps to Revert a Commit:
-
Identify the Commit Hash: Use
git logto find the commit hash of the commit you want to revert.git log -
Revert the Commit: Use the
git revertcommand with the commit hash.git revert <commit_hash> -
Edit Commit Message (Optional): If your default text editor opens, you can either accept the default commit message or modify it. Save and close the editor to finalize the revert.
Example:
If you want to revert a commit with the hash 3050fc0d3, you would run:
git revert 3050fc0d3
After executing this command, Git will create a new commit that undoes the changes made by the specified commit.
