Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The basic approach is to define a custom merge tool and then use the git attributes feature to tell git to use that custom merge tool for those files.</p> <p>Example:</p> <ol> <li><p>create a test repository:</p> <pre><code>$ git init t $ cd t </code></pre></li> <li><p>define a custom merge tool called <code>mymerge</code>:</p> <pre><code>$ git config merge.mymerge.name "my custom merge tool" $ git config merge.mymerge.driver "cat '%A' '%B'|sort -u &gt;'%A'.tmp &amp;&amp; mv '%A'.tmp '%A'" </code></pre> <p>The above merge tool concatenates the files, sorts the resulting lines, and then removes duplicate lines. If you don't want to change the order, replace the above command with a custom script that does what you want. See <code>git help attributes</code> for more information.</p></li> <li><p>tell git that you want to use <code>mymerge</code> when merging any file named <code>foo.txt</code> in the repository:</p> <pre><code>$ echo "foo.txt merge=mymerge" &gt;.gitattributes $ git add .gitattributes $ git commit -m "tell git to use the mymerge merge tool for foo.txt" </code></pre></li> <li><p>make some test data on three branches:</p> <pre><code>$ printf 'apple\nkiwi\nstrawberry\n' &gt;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' &gt;foo.txt $ git commit -a -m "add orange" $ git checkout -b pear master $ printf 'apple\nkiwi\npear\nstrawberry\n' &gt;foo.txt $ git commit -a -m "add pear" </code></pre></li> <li><p>merge the branches (note no conflicts!):</p> <pre><code>$ git checkout master $ git merge orange $ git merge pear </code></pre></li> <li><p>profit!</p> <pre><code>$ cat foo.txt apple kiwi orange pear strawberry </code></pre></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload