How to Revert a Merge Commit Already Pushed to the Remote Branch in Git

The out­come of this revert is that Git will cre­ate a new com­mit that rolls back the changes from the merge. We have amy_feature_branch that I’ve been work­ing in. We also have adevelop branch that I merge into and deploy to my testing/​staging server.

This is super important and should be added as a warning to the other answers. IMO you are not really reversing the merge itself, you are reversing the changes made by the merge. With -n or –no-stat do not show a diffstat at the end of the merge.


Among the changes made to the common ancestor’s version, non-overlapping ones are incorporated in the final result verbatim. When both sides made changes to the same area, however, Git cannot randomly pick one side over the other, and asks you to resolve it by leaving what both sides did to that area. With –ff, when possible resolve the merge as a fast-forward (only update the branch pointer to match the merged branch; do not create a merge commit). When not possible (when the merged-in history is not a descendant of the current history), create a merge commit. Incorporates changes from the named commits into the current branch.

git revert merge commit

With –no-commit perform the merge and stop just before creating a merge commit, to give the user a chance to inspect and further tweak the merge result before committing. When working with Git and you want to revert a merge commit, you need to indicate which parent commit you want to revert to. For example, you may want to improve or set up your code review process. You can also define code owners to make sure the appropriate eyes are on your pull requests before they get merged. The docs for `revert` explain how that works here. Occasionally, you can get into a situation where you make a merge, commit it, and maybe even push it to your remote server before realizing there’s an issue with it. When this happens, you’ll need a way to get your main branch back to its previous state.

Undoing a merge after push

So I decided to add an answer with simple straightforward steps for cases like mine.. I create a new branch from a, cherry pick c and d and then the new branch is clear from b.

  • Just make sure you understand that if you revert the merge commit, you can’t just merge the branch again later and expect the same changes to come back.
  • Level 5 and above outputs debugging information.
  • We save your time by prioritizing and automatically merging, commenting, rebasing, updating, labeling, backporting, closing, assigning, your pull requests.
  • When set to only, only such fast-forward merges are allowed (equivalent to giving the –ff-only option from the command line).
  • It is therefore recommended to always commit or stash your changes before running git merge.

If not specified, defaults to the value of diff.renameLimit. If neither merge.renameLimit nor diff.renameLimit are specified, currently defaults to 7000. This setting has no effect if rename detection is turned off. An element with an empty value can be used to clear the list of globs accumulated from previous configuration entries. When there is no merge.suppressDest variable defined, the default value of master is used for backward compatibility.

Sharing and Updating Projects

It is possible to have modifications in the working tree as long as they do not overlap; the update will preserve them. Except in a fast-forward merge , the branches to be merged must be tied together by a merge commit that has both of them as its parents. But merging can also make for a mean headache if you make a mistake. A bad merge can detract from your project’s historical continuity, confuse fellow contributors, and potentially slow down development for all involved.

git revert merge commit

Article was published on: 10/20/22

Author: Viktor Nikolaev

Victor is a professional crypto investor and stockbroker, specializing in such areas as trading on the stock exchange, cryptov currencies, forex, stocks and bonds. In this blog he shares the secrets of trading, current currency indices, crypt currency rates and tells about the best forex brokers. If you have any questions, you can always contact

Leave a Reply