How to Undo Git Commit Amend Done Instead of Git Commit

Git is a widely used version control system among developers and is considered a crucial tool for maintaining the source code of software projects.

However, sometimes mistakes can happen, such as when you use the wrong Git command and end up amending a commit instead of creating a new one.

In this tutorial, we will guide you through the steps of undoing a Git commit amend and help you get back on track.


Check the Commit History

Before you start, it’s important to check the commit history to see the changes you made using the Git commit amend command.

To do this, you can use the following command:

git log

Revert the Amend Commit

To undo the amend commit, you need to use the “git reset” command with the “–soft” option and specify the commit ID.

The “–soft” option will reset the branch pointer to the specified commit and leave the working tree and index intact.

Here’s the command you need to use:

git reset --soft <commit_id>

Create a New Commit

After you have successfully undone the amend commit, you can create a new commit with the changes you made.

You can use the following command to add the changes to the index:

git add .

And then, you can use the following command to create a new commit:

git commit -m "Your commit message"

Push the Changes

Finally, you need to push the changes to the remote repository.

You can use the following command to do this:

git push origin <branch_name>

Conclusion

In this tutorial, we have shown you how to undo a Git commit amend and get back on track.

It’s important to be mindful of the Git commands you use and to check the commit history before making any changes.

If you follow these steps, you will be able to undo a Git commit amend in no time.