How can I drop a branch from merging branches with malit structure in git?

I simply merged three different branches together as part of a feature set and pushed the results so that the repository tree looked like this:

  --- A --- A1 --- A2 --- A3 -
     |  \
     + --- B1 --- B2 --- B3 --- B4-
     |  \
     + --- C1 --- C2 --- C3 --------- C4

However, I was just told that branch B not ready for prime time, so I need to cancel these commits. How can I undo my changes so that my new chapter C5 to merge C3 and A3 ? When I'm done, I want the repository to look like this:

  + --- B1 --- B2 --- B3 --- B4 --- B5
     |  /
 --- A --- A1 --- A2 --- A3 -
     |  \
     + --- C1 --- C2 --- C3 --- C4 --- C5
+4
source share
4 answers
 # checkout before merge git checkout C3 # make merge we want git merge A3 # rebase any work on top of the new merge git rebase --onto HEAD C4 branch_C # use fixed version as branch_C git branch -f branch_C HEAD # aha! now you on the fixed branch_C git checkout branch_C 

Do the same with B. I believe that after the "bad" merge you did not enter C and B.

+1
source

I am from a camp that prefers to redo the bot-up until it is pressed to leave a less detailed history, and I usually do like this:

 # go back to commit C3 git checkout C3 # redo the merge with only A git merge branch_A # make sure you've gotten the desired alteration # git diff --stat branch_C # git diff branch # switch your C branch over to your redone version git checkout -B branch_C # otherwise if you change your mind, just go back to C4 # git checkout branch_C 

Edit: Comment No. 4 was perfectly true that the previous version of this did not lead to anything. This change modifies the git merge line that previously merged with B4 . The --detach option --detach also been removed from the original check, as it is redundant if the C3 argument is not a branch name.

+3
source

Return C4 (and fix this reversal), then merge A3 into the newly created C5.

 --- A --- A1 --- A2 --- A3 ----------------------------- | \ \ + --- B1 --- B2 --- B3 --- B4- \ | \ \ + --- C1 --- C2 --- C3 ---------C4--- C5(reverts C4) -- C6 

As a result, you get B4 containing B3 + A3, and C6 containing C3 + A3.

I suppose you could do all this by reloading too, but I prefer to leave my tracks when I was doing something dirty, so I can see both my mistake and what I did to fix it. Rebase cancels the story, which makes me twitch.

+2
source

Assuming you have not shared this repository with anyone else, you can try git rebase --onto .

 git rebase --onto <to> <from> <what> 

I assume your branches are called A (on A3), B (on B4) and C (on C4):

 git rebase --onto B3 A3 C 

Where B3 and A3 are actually SHA ships.

I highly recommend backing up your repository before running this command in order to play it from the safe side.

0
source

Source: https://habr.com/ru/post/1394259/


All Articles