git(hub) remove commit from a merge
My question in similar to git remove commit from a merge but I can't follow instructions suggested there, since my repository's history is a little bit different.
I'm working on a open-source repository on github. After few months I wanted to update my local repository and I made a useless merge-commit by mistake. The history looks like below:
* commit 3d542ddb64e6474a10dfface24defc69b713a295 | Author: TD | | fixed typo in dependency_injection/compilation chapter | * commit 34db3b8c08e5c5d3be4021076716ed90187fe5fb |\ Merge: b8b73fb 7cc08f4 | | Author: TD | | | | Merge remote-tracking branch 'upstream/master' | | | * commit 7cc08f476b7ac5610b1eb5b5db5182d18e35a9e9 | | Author: RW | | | | [#1654] Tweaking comments ...
There should be just one commit with my small change, but there are two. I just want to remove the 34db3b8c0... merge commit. I know I should try interactive rebase, but I don't know how to set it up. When I try
git rebase -i HEAD~2
I get a huge list of past commits:
pick bbfbddb Add the new "strict_requirements" pick 31bb8a9 [reference] Tweaking note about strict_requirements pick fb4d621 [Cookbook][Extension] Fixed typo in functions name pick d8d1d86 Fixing index typo # lots and lots of commits in the history here pick c734436 Fixed indentation. pick ca8d884 Update cookbook/logging/channels_handlers.rst pick 7cc08f4 [#1654] Tweaking comments in channel handlers doc to point to reference pick 3d542dd fixed typo in dependency_injection/compilation chapter: should be contAiner instead of continer # Rebase b8b73fb..3d542dd onto b8b73fb # # Commands: ...
But when I try:
git rebase -i HEAD~1
(wanna have a shorter list) I get only one commit:
pick 3d542dd fixed typo in dependency_injection/compilation chapter: should be contAiner instead of continer
As far as I understood, I should squash the merge commit 34db3b8c08... using interactive rebase, right?
Thanks for any help.
Try git rebase upstream/master. So, your commit will be applied at the remote master. The merge commit will be dropped as useless.
What you want to do is take all of the changes since the merge and rebase them onto the commit before the merge:
git rebase --onto 34db3b8^ 34db3b8 master
where "34db3b8" is the merge commit you want to eliminate, and "master" is the branch you want to eliminate it from. This will rewrite the branch, skipping the merge commit and replaying everything after it.