Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Many thanks to @VonC for suggesting the use of the <strong>merge=custom-driver</strong> attribute in the <strong><em>.gitattributes</em></strong> file. While this will work, I'm reluctant to pollute my workspace with .git files, and while I could use <strong><em>$GIT_DIR/info/attributes</em></strong> to avoid the pollution, I'm bothered by the need for 2 rules to catch dot-files and non-dot files.</p> <p>After a bit of experimentation I managed to get a solution with the <strong>merge.default</strong> configuration variable (mentioned in the <em>gitattributes(5)</em> manpage) working. The trick I missed was that <strong>merge.default</strong> takes the <em>name</em> of a custom driver you have defined previously; you don't give it the <em>custom command</em> directly. Here's what works for me...</p> <p>First define your copy-merge custom driver. You can use shell commands directly; there's no need for an external script (just make sure you get your shell meta-character quoting right):</p> <pre><code>git config merge.copy-merge.name 'Copy Merge' git config merge.copy-merge.driver 'mv %B %A' </code></pre> <p>Note that mv returns 0 on success, 1 on failure, meeting the criteria for reporting merge "success" back to git.</p> <p>Now tell git that ALL merges are copy-merges:</p> <pre><code>git config merge.default copy-merge </code></pre> <p>Hey Presto! Job done. <strong>git merge &lt;branch&gt;</strong> will now copy-merge everything so the branch you're on contains exact copies of all files on &lt;branch&gt;. QED.</p> <p>If you want to do a non-copy-merge then simply reset the default merge driver:</p> <pre><code>git config --unset merge.default </code></pre> <p>If you do want to be more selective then leave <strong>merge.default</strong> unset and use attributes as @VonC says:</p> <pre><code>cd path/to/copy-merge/in echo '* merge=copy-merge' &gt; .gitattributes echo '.* merge=copy-merge' &gt;&gt; .gitattributes </code></pre> <p>Do this at the top of every subtree you want to copy-merge in. If there's a sub-subtree that you DON'T want to copy-merge in, you can turn it off again:</p> <pre><code>cd path/to/copy-merge/in/path/to/normal-merge/in echo '* merge' &gt; .gitattributes echo '.* merge' &gt;&gt; .gitattributes </code></pre> <p>WARNING: littering your working tree with lots of .gitattributes files is bound to lead to confusion, especially if you also use things like "*.bin -merge" in other directories to force all merges of .bin files to fail with conflicts. It may be better to use <strong><em>$GIT_DIR/info/attributes</em></strong> for this sort of thing, as it has the highest precedence.</p>
 

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