Navigate to Your Repository:
Open your terminal
Check the Status:
Run the following command to ensure you have a clean working tree:
git status
Find the Commit Hash:
Each commit has a unique hash (e.g., 2c8451a). You need to find the hash of the commit you want to undo.
You can do this in two ways:
- View the commit history on GitHub, Bitbucket, or another remote repository hosting service;
- View the commit history in the terminal
Let's use the terminal.
git log --oneline
Output
Revert the Commit:
Once you have the commit hash, run the following command (replacing 2c8451a with the actual hash of your commit):
git revert 2c8451a --no-edit
The --no-edit
option prevents Git from asking you to enter a commit message.
OUtput
By following these steps, you will create a new commit that effectively undoes the specified commit while keeping your Git history intact.
Push the Reverted Changes
if working with a remote repository):
git push origin feature/branch-133
This will push the reverted commit to the remote repository, ensuring that others see the changes.
Double check
In the terminal:
git log --oneline
Output
Top comments (0)