DEV Community

Alexandre Calaça
Alexandre Calaça

Posted on

How to undo a specific pushed commit

Navigate to Your Repository:

Open your terminal


Check the Status:

Run the following command to ensure you have a clean working tree:

git status
Enter fullscreen mode Exit fullscreen mode

Image Check the 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
Enter fullscreen mode Exit fullscreen mode

Output

Image Find the Commit Hash


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
Enter fullscreen mode Exit fullscreen mode

The --no-edit option prevents Git from asking you to enter a commit message.

OUtput

Image Revert the Commit

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
Enter fullscreen mode Exit fullscreen mode

This will push the reverted commit to the remote repository, ensuring that others see the changes.


Double check

In the terminal:

git log --oneline
Enter fullscreen mode Exit fullscreen mode

Output

Image Double check


Done


Final message

Top comments (0)