Combine conflict resolution with new code

Say I have a code that is streamlined, but ordering is not a technical requirement.

apple
kiwi
strawberry

And I have two themes that I want to combine, whose differences are as follows:

TOPIC BRANCH: orange
  kiwi
+ orange
  strawberry

And

TOPIC BRANCH: pear
  kiwi
+ pear
  strawberry

Is there a way for these two patches to be automatically resolved? It seems to me that this is a merger conflict because they are competing for the same new line. The solution I came up with is changing the order of one of the changes, since the sort order is just a soft requirement (where the fruits are actually function definitions).

 TOPIC BRANCH: pear'
   apple
 + pear
   kiwi

So, now we can combine orangeand pear'together to form:

 _ apple
 p pear
 _ kiwi
 o orange
 _ strawberry

, ? , pear orange, orange , . , orange pear .

, .

: , ( , ?) , " " " ", , .

+5
2

, , git, git .

:

  • :

    $ git init t
    $ cd t
    
  • mymerge:

    $ git config merge.mymerge.name "my custom merge tool"
    $ git config merge.mymerge.driver "cat '%A' '%B'|sort -u >'%A'.tmp && mv '%A'.tmp '%A'"
    

    , . , script, , . . git help attributes.

  • git, mymerge foo.txt :

    $ echo "foo.txt merge=mymerge" >.gitattributes
    $ git add .gitattributes
    $ git commit -m "tell git to use the mymerge merge tool for foo.txt"
    
  • :

    $ printf 'apple\nkiwi\nstrawberry\n' >foo.txt
    $ git add foo.txt
    $ git commit -m "common ancestor version of foo.txt"
    $ git checkout -b orange
    $ printf 'apple\nkiwi\norange\nstrawberry\n' >foo.txt
    $ git commit -a -m "add orange"
    $ git checkout -b pear master
    $ printf 'apple\nkiwi\npear\nstrawberry\n' >foo.txt
    $ git commit -a -m "add pear"
    
  • ( !):

    $ git checkout master
    $ git merge orange
    $ git merge pear
    
  • !

    $ cat foo.txt
    apple
    kiwi
    orange
    pear
    strawberry
    
+7

, , , , , , . git . git, , - , , , .

0

All Articles