How to Revert Git Commit already Pushed to Remote Repo?

How to Revert Git Commit already Pushed to Remote Repo?

How to Revert Git Commit already Pushed to Remote Repo?

Did you committed and pushed the wrong changes to your remote Git repo?

No worries. This happens many times with many of us.

In this tutorial, I will demonstrate how you can revert git commit that has already pushed to the remote repo.

I assume you have a basic understanding of the Git like what is Git commit, branch, checking out to the branch locally?

If you are new to the Git, you can follow the complete Git tutorial.

Now, let’s follow the steps to revert git commit.

It’s just a two-steps process to undo the commit. But, execute them carefully to avoid any further wrongdoing.

git tutorial

Step 1: Revert the Committed Changes Locally

For this, you need the commit ID. Every commit has a commit ID. With this commit ID, you can revert your changes back.

Here is the syntax of the git revert command.

git revert <commit_id>

It will create the new commit by deleting all the changes that had gone as part of the commit.

As of now, all the reverted changes are locally present. You need to push them to the remote repository.

Step 2: Push the Commit to Remote Repo

Here is the git command to push the local changes to the remote repository.

git push origin <branch_name>

Make sure you give the correct branch name.

That’s all.

You can log in to your remote repository. Look into the commit list or the code changes. You have reverted changes that you had made as a part of the wrong commit.

Do you have any questions or any challenges executing the command to revert git commit? Let me know by commenting below. Stay tuned for more Git tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *