I'm looking for a way to remove an "double" commit I accidentally created on a repo. While attempting to collapse a branch's commits before merging it into the master, I unwittingly pushed the branch's changes onto the master (I know just enough Git to shoot myself in the foot). Later, when I merged the branch, I ended up with a second (merge) commit. The changes in this merge commit are exactly the same as those in the accidentally pushed commit. Now my master commit history looks something like this:
Some_Newer_Stuff_Here
The_Merge_Commit
The_Branch_Commit //Same contents, different Hash as commit above
Master_Commit_2
Master_Commit_1
I have attempted to use git interactive rebase (as detailed here and here), however when I do so, not all the commits appear in the list. Instead I see something like this:
Some_Newer_Stuff_Here
The_Branch_Commit
Master_Commit_2
The_Merge_Commit is missing (which I assume is the one I want to keep). Note that all commits do show up in git log. If I attempt to remove The_Branch_Commit using rebase it creates a bunch of merge conflicts.
I can't find any way to solve this problem, so any help would be appreciated.
Without more commit information, I'm not able to give you specific, step by step instructions. But I thought I could potentially answer one of the aspects of your question.
The reason that
The_Merge_Commitdoesn't show up in the interactive rebase is because thegit rebasecommand by default ignores merge commits, instead preferring to lay commits one on top of the next.You can change this behavior with the
--preserve-mergesflag however. Adding that to yourgit rebase -icommand will causeThe_Merge_Committo show up in the editor page, and then you would be able to deleteThe_Branch_Commit. But there is still the potential for some annoying merge conflicts to happen.