GIT Revert

Multiple Commits

How to

Problem ?

Sometimes, you commit and merge the code that breaks something or any other reasons on the application. To resolve this problem, this Git feature help you to rollback the broken code from the main branch.


Let’s say you have accidentally merged the code that you are not ready to. And you want to go back to the previous stage.

Step 1. Get Last Log Details

git log


There is a particular COMMIT_ID that defines the commit that we had done earlier. For ex.

Step 2. Get the last Commit ID

commit b34bdh434gfg5d4ny7


The git revert command is used for undoing changes to a repository’s commit history.

Step 3. Revert Commit

git revert COMMIT_ID


Previous command will revert the last commit from the local repository. You need to run push to change the same thing on the remote repository as well.

Step 4. Push the Commit

git push

That's It

Finally🙌, you have safely reverted or undo the last commit from the main branch. in this way you can roll back a mistaken or unwanted merge and work more efficiently with Git.