Search code examples
gitrevertgitkraken

Delete a Branch That Comes With Other Merged Branch


I have 3 branches;

A: Main branch that we use for testing.

B: The branch that has changes those must be in A branch.

C: The branch that has changes those must NOT be in A branch.

So, while I was working on B, I merged C into B and continued to working on B. At the end I merged B into A.

I want to delete all C commit from A but keep B branch in A.

I'm using GitKraken, but every suggestion will be accepted.


Solution

  • If the branch C is not too big, I would just use "git revert". In GUI clients like GitKraken you can usually right-click on a commit and "Revert" it.

    For example if your C branch has commits [C1, C2] (in this order), you should revert C2 first, and then C1:

    git revert C2
    git revert C1
    

    Note: replace C1 here with the SHA of C1 commit.

    If one of the reverts is not happening cleanly, you need to find and resolve conflicts.

    If your merge of C into B was not a fast-forward merge, but produced a merge commit, you can find that merge commit in the history log - "Cm" - and try to revert just that single commit:

    git revert Cm
    

    If you have more than 3 or so commits in C, I would try to reset A to the previous state (before B was merged), preparing a new clean version of B - call it B2 - and merging B2 into A.