Reputation: 1
I have two parallel projects with two branches A and B.
Each branch was supposed to be developed separately and merged later when the development is complete.
By mistake, I merged branch B twice into branch A prematurely. After the merge, there were more commits made to both branches.
The merge contains some new files that have been created to branch B, and there are also few files that are shared in both branch A and branch B which have been modified by branch B.
What I want to do is, revert the merge that happened in branch A, and then continue the development of branch A and branch B (make more commits to both branches after the revert), and then be able to merge these branches again at a later point.
I did some research here and came up with the following scenario. Can someone more familiar with git advise if this is a good way to go about what I want to achieve?
Let's say the merge commit is: 123
git revert -m 1 123
(commit all deletions into branch A as a result of the revert)
continue the work on branch A and branch B separately.
at a later point, merge these two branches again. I would first create a new branch C based off of A. And then I would revert the original revert in branch C. And then I would merge branch B to branch C.
git checkout -b C
git revert 123
git merge B
Does this sound like the right way to approach this problem?
Any help would be appreciated. Thanks in advance.
Upvotes: 0
Views: 2046
Reputation: 3198
A merge is basically just a commit with two parents that lives on one of the merged branches. That being said one of the branches (B in your case) is never changed while the merges are just commits on branch A.
So yes you can just revert them an continue working as if nothing happend (assuming the commits are recent enough that the revert produces nice results).
You can later on merge them without reverting the revert because the new merge will include the old merge (don't know if that sentence made sense).
So your approach would be
Also there is now a chapter on undoing merges with strategies on this (I have just skimmed it)
Upvotes: 1