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 commit and push 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 the git commit that has already been pushed to the remote repo.

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

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

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

It’s just a two-step 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 a new commit by deleting all the changes that had gone as part of the commit.

For more details about commit ID and reverting the git commit from the local repo, check remove git commit from the local repo.

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 *