Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need to remove merging branches, but save subsequent commits (git)

DenisNagorny
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 15, 2019

Branch develop22 finished a three monts ago(was created from master).  After that developers worked with branch master. But 20 days ago develop22 pushed into master(but before master wasn't pushed into develop22). After that developers do not suspect about this issue still worked more than 10 days. 

I need to remove this merge commit, but save subsequent commits.  

I know we can use revert this commit and after use cherry-pick for each subsequent commit, but this is really long way.

Anyone can help with much optimistic way?

1 answer

1 accepted

1 vote
Answer accepted
Mikael Sandberg
Community Champion
May 15, 2019

Hi Denis,

Welcome to the Atlassian Community.

I have done these reverts in the past, they are not fun to do but can be done. Here are the steps I use:

  1. Revert the merge on the master branch
  2. Checkout your branch that you want to merge again, in this case develop22.
  3. Create a new branch that will be used to recreate the commits on the old branch and checkout the new branch.
  4. Use git log --graph --oneline --all to locate the commit where the old branch was branched off from.
  5. Run git rebase --no-ff <parent commit> to rebase the new branch based on the parent commit. This will replay the commits that were made on the old branch.

You can now merge this new branch into the target and be sure that your reverted changes once again will be included.

Here is Linus Torvalds explanation of the situation and why you need a new branch:

Reverting a regular commit just effectively undoes what that commit did, and is fairly straightforward. But reverting a merge commit also undoes the _data_ that the commit changed, but it does absolutely nothing to the effects on _history_ that the merge had.

So the merge will still exist, and it will still be seen as joining the two branches together, and future merges will see that merge as the last shared state - and the revert that reverted the merge brought in will not affect that at all.

So a "revert" undoes the data changes, but it's very much _not_ an "undo" in the sense that it doesn't undo the effects of a commit on the repository history.

So if you think of "revert" as "undo", then you're going to always miss this part of reverts. Yes, it undoes the data, but no, it doesn't undo history.

DenisNagorny
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 15, 2019
  1. Use git log --graph --oneline --all to locate the commit where the old branch was branched off from.

 

what i have to do use that: 

  1. Use git log --graph --oneline --all to locate the commit where the old branch was branched off from.

just to find parent commit? :)

i can use another soft like gitk or gitkraken 

thank you very much:)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events