Revert a merge commit in Git that's already pushed to remote

Git is an important tool for managing projects. It would be bad if there weren’t a way to undo things, for example, commits. This is because we often make mistakes while building.

Here’s a guide on how to revert a merge commit in Git that’s already pushed to the remote.

Let’s get down to it.

Revert a merge commit in Git that’s already pushed

Reverting a merge commit that’s already pushed to Remote is easy. There are simply two Git commands that we’ll use:

  1. The Git log command: The git log is used to pull up project history in Git. It makes it easy to see our changes and helps debug. To see our project history, run the following command:

git log

  1. The Git revert command: The git revert is used for undoing things in Git. It is used to undo changes of a commit in a git repository. It takes a particular commit and reverses its changes but will not return your project to its previous state. Run it with the hash of the particular commit you want to revert.

git revert git-commit-hash

How to revert a merge commit

  • Step 1: Get the history of your project. Getting the history is made to get the hash of the commit we wish to revert. Run git log.

The result looks like this:


commit 465006cef583dac8a01855a996f95b321a208f7e
Merge: 675a7e5 76db734 
Author: Akande Olalekan Toheeb <akandeoalalekantoheeb9@gmail.com>
Date: WED NOV 16 19:30:24 2020 +0100 Merge branch 'GH-pages' Conflicts: README

Note: Merge Commits have two parent commits. Therefore, there will be two hashes of the merge commit.

  • Step 2: Revert the merge commit using the git revert command.

    Since it’s a merge commit, you run the git revert command with either of -m 1 or -m 2 option.

git revert git-commit-hash  -m 1

Note: -m 1 instruct Git to revert the first parent of the merge commit while -m 2 reverts the second.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved