To revert a commit in Git, you can use the git revert command. This command creates a new commit that undoes the changes made by a specific commit without altering the commit history.
Steps to Revert a Commit:
-
Identify the Commit: First, find the commit hash of the commit you want to revert. You can do this by running:
git log -
Revert the Commit: Use the
git revertcommand followed by the commit hash. For example:git revert <commit-hash>Replace
<commit-hash>with the actual hash of the commit you want to revert. -
Commit Message: Git will open your default text editor to allow you to enter a commit message for the revert. You can modify it or keep the default message.
-
Complete the Revert: Save and close the editor to complete the revert process.
Example:
If you want to revert a commit with the hash 3050fc0d3, you would run:
git revert 3050fc0d3
This will create a new commit that undoes the changes introduced by the specified commit, preserving the history of your repository.
