Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy the a resolved git merge to another merge

Tags:

git

In my git workflow i have to merge a feature branch into master. However while i am resolving merge conflicts, somebody has pushed a new commit to feature and master.

I have then to generate a new merge commit, based on new feature and new master. However 90 % of the merge conflicts are still the same. So my question is. Can i save my progress from the first merge, and apply it in the conflict phase of the new merge ?

 +--------+        +--------+             +------------+
 |        |        |        |             |            |
 |  init  +------> | master +-----------> | new master |
 |        |        |        |             |            |
 +--------+        +--------+             +------------+
       |                 |                             |
       |           +---------+            +-------------+
       |           |         |            |             |
       +---------> | feature +----------> | new feature |
                   |         |            |             |
                   +---------+            +-------------+
                    |    |                            ||
                    |    |                            ||
                    |    |      +----------------+    ||        +-----------+
                    |    +----> |                |    +--------->           |
                    |           |   first merge  |    |         | new merge |
                    +----------->                |    +--------->           |
                                +----------------+              +-----------+
like image 706
mac.1 Avatar asked May 29 '17 09:05

mac.1


People also ask

What is merge conflict?

A merge conflict is an event that occurs when Git is unable to automatically resolve differences in code between two commits. When all the changes in the code occur on different lines or in different files, Git will successfully merge commits without your help.


1 Answers

Git has a feature called rerere. It can be used at this situation. Enable rerere in config file and it just works. I think it is the right way to resolve this problem.

https://git-scm.com/blog/2010/03/08/rerere.html

https://git-scm.com/docs/git-rerere

To use this feature without enabling it in advance, the script https://github.com/git/git/blob/master/contrib/rerere-train.sh can help you.

Maybe there is a simple method to do it. Merge new feature to first merge and then merge the result to new master.

like image 134
crvv Avatar answered Oct 03 '22 18:10

crvv