From c2ffba97eb0b5456fc49e98c671c9666f0537eea Mon Sep 17 00:00:00 2001 From: abdel ali <35116901+a6delali@users.noreply.github.com> Date: Tue, 17 Jul 2018 22:59:17 +0100 Subject: [PATCH] I committed and pushed a merge that shouldn't have happened (#213) --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 5c1c561..c1ef5ae 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ For clarity's sake all examples in this document use a customized bash prompt in - [Delete/remove arbitrary commit](#deleteremove-arbitrary-commit) - [I tried to push my amended commit to a remote, but I got an error message](#i-tried-to-push-my-amended-commit-to-a-remote-but-i-got-an-error-message) - [I accidentally did a hard reset, and I want my changes back](#i-accidentally-did-a-hard-reset-and-i-want-my-changes-back) + - [I accidentally committed and pushed a merge](#i-accidentally-committed-and-pushed-a-merge) - [Staging](#staging) - [I need to add staged changes to the previous commit](#i-need-to-add-staged-changes-to-the-previous-commit) - [I want to stage part of a new file, but not the whole file](#i-want-to-stage-part-of-a-new-file-but-not-the-whole-file) @@ -291,6 +292,19 @@ You'll see a list of your past commits, and a commit for the reset. Choose the S And you should be good to go. + +### I accidentally committed and pushed a merge + +If you accidentally merged a feature branch to the main development branch before it was ready to be merged, you can still undo the merge. But there's a catch: A merge commit has more than one parent (usually two). + +The command to use +```sh +(feature-branch)$ git revert -m 1 +``` +where the -m 1 option says to select parent number 1 (the branch into which the merge was made) as the parent to revert to. + +Note: the parent number is not a commit identifier. Rather, a merge commit has a line `Merge: 8e2ce2d 86ac2e7`. The parent number is the 1-based index of the desired parent on this line, the first identifier is number 1, the second is number 2, and so on. + ## Staging