Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Update 2013:</p> <p>More recent git versions authorize using merge with strategy <code>recursive</code> and strategy <em>option</em> (<code>-X</code>):</p> <ul> <li>from "<a href="https://stackoverflow.com/a/5262473/6309">Git Merge and Fixing Mixed Spaces and Tabs with two Branches</a>":</li> </ul> <pre> git merge -s recursive -Xignore-space-at-eol </pre> <p>But using "<code>-Xignore-space-change</code>" <a href="https://stackoverflow.com/a/13415932/6309">is also a possibility</a></p> <ul> <li><a href="https://stackoverflow.com/users/1441706/fab-v">Fab-V</a> mentions <a href="https://stackoverflow.com/a/16054884/6309">below</a>: <pre> git merge master -s recursive -X renormalize </ul> <hr> <p><a href="https://stackoverflow.com/users/245966/jakub-g">jakub.g</a> also <a href="https://stackoverflow.com/questions/861995/is-it-possible-for-git-merge-to-ignore-line-ending-differences/862920?noredirect=1#comment41273803_862920">comments</a> that the <strong>strategies work also with cherry-picking</strong>: </p> <pre><code>git cherry-pick abcd123456 --strategy=recursive --strategy-option=renormalize </code></pre> <p>This works much better than <code>ignore-all-space</code>.</p> <hr> <p>Original answer (May 2009)</p> <p>The patch for ignoring eol style has been proposed in <a href="http://kerneltrap.org/index.php?q=mailarchive/git/2007/6/28/250172/thread" rel="noreferrer">June 2007</a>, but it only concerns <code>git diff --ignore-space-at-eol</code>, not <code>git merge</code>.</p> <p>At the time, the question has been askeed:</p> <blockquote> <p>Should <code>--ignore-space-at-eol</code> be an option to <code>git-merge</code> ?<br> Merges are where this functionality matters.<br> What are the semantics of an auto-resolved merge with those options in effect -- are they only used for rename detection, or do we, e.g., not flag conflicts with only whitespace changes ? And if we don't, which version do we accept automatically ?</p> </blockquote> <p>Julio C Hamano was not exactly enthusiastic:</p> <blockquote> <p>This certainly is tempting, but I suspect that should be left to later rounds.<br> I suspect that it would introduce a concept of two different kinds of diffs, one to be mechanically processed (i.e. use in merge with "git-merge-recursive", and apply with "git-am"), and another to be inspected by humans to understand.<br> It often may be useful to munge the input for the latter case, even though the output from comparing munged input files may not be readily usable for mechanical application.</p> </blockquote> <p><strong>The general idea, when it comes to <code>git merge</code>, is to rely on the third-party merge tool.</strong></p> <p>For instance, I have setup <a href="http://sourcegear.com/diffmerge/" rel="noreferrer">DiffMerge</a> to be the tool for Git merge, setting a <strong>ruleset</strong> which allow that merge tool to ignore eol for certain type of files.</p> <hr> <p>Setup on Windows, with MSysGit1.6.3, either for DOS or Git bash session, with DiffMerge or KDiff3:</p> <ul> <li>set a directory into your PATH (here: <code>c:\HOMEWARE\cmd</code>).</li> <li>add in that directory the script merge.sh (wrapper for your favorite merge tool)</li> </ul> <p>merge.sh:</p> <pre><code>#!/bin/sh # Passing the following parameters to mergetool: # local base remote merge_result alocal=$1 base=$2 remote=$3 result=$4 if [ -f $base ] then #"C:/Program Files/SourceGear/DiffMerge/DiffMerge.exe" "$alocal" "$base" "$remote" -m --result="$result" --title1="Mine" --title2="Merging to: $result" --title3="Theirs" # for merge respecting eol, KDiff3 is better than DiffMerge (which will always convert LF into CRLF) # KDiff3 will display eol choices (if Windows: CRLF, if Unix LF) "C:/Program Files/KDiff3/kdiff3.exe" -m "$base" "$alocal" "$remote" -o "$result" else #there is not always a common ancestor: DiffMerge needing 3 files, BASE will be the result #"C:/Program Files/SourceGear/DiffMerge/DiffMerge.exe" "$alocal" "$result" "$remote" -m --result="$result" --title1="Mine" --title2="Merging to: $result" --title3="Theirs" # KDiff3 however does know how to merge based on 2 files (not just 3) "C:/Program Files/KDiff3/kdiff3.exe" -m "$base" "$remote" -o "$result" fi </code></pre> <ul> <li>Declare your merge wrapper for Git</li> </ul> <p>Git config commands:</p> <pre><code>git config --global merge.tool diffmerge git config --global mergetool.diffmerge.cmd "merge.sh \"$PWD/$LOCAL\" \"$PWD/$BASE\" \"$PWD/$REMOTE\" \"$PWD/$MERGED\" git config --global mergetool.diffmerge.trustExitCode false git config --global mergetool.diffmerge.keepBackup false </code></pre> <ul> <li>Check that autoCRLF is false</li> </ul> <p>git config at system level:</p> <pre><code>git config ---system core.autoCRLF=false </code></pre> <ul> <li><strong>Test that, when two lines are identical (but their eol chars), both DiffMerge or KDiff3 will ignore those line during a merge.</strong></li> </ul> <p>DOS script (note: the <a href="http://www.bastet.com/" rel="noreferrer">dos2unix command comes from here</a>, and is used to simulate a Unix eol-style. That command has been copied in the directory mentioned at the beginning of this answer.):</p> <code>C:\HOMEWARE\git\test&gt;mkdir test_merge C:\HOMEWARE\git\test&gt;cd test_merge C:\HOMEWARE\git\test\test_merge&gt;git init C:\HOMEWARE\git\test\test_merge&gt;echo a1 &gt; a.txt &amp; echo a2 &gt;&gt; a.txt C:\HOMEWARE\git\test\test_merge&gt;git add a.txt C:\HOMEWARE\git\test\test_merge&gt;git commit -m "a.txt, windows eol style" C:\HOMEWARE\git\test\test_merge&gt;git checkout -b windows Switched to a new branch 'windows' C:\HOMEWARE\git\test\test_merge&gt;echo a3 &gt;&gt; a.txt &amp; echo a4 &gt;&gt; a.txt C:\HOMEWARE\git\test\test_merge&gt;git add a.txt C:\HOMEWARE\git\test\test_merge&gt;git commit -m "add two lines, windows eol style" C:\HOMEWARE\git\test\test_merge&gt;git checkout master C:\HOMEWARE\git\test\test_merge&gt;git checkout -b unix Switched to a new branch 'unix' C:\HOMEWARE\git\test\test_merge&gt;echo au3 &gt;&gt; a.txt &amp; echo au4 &gt;&gt; a.txt &amp;&amp; echo au5 &gt;&gt; a.txt C:\HOMEWARE\git\test\test_merge&gt;dos2unix a.txt Dos2Unix: Processing file a.txt ... C:\HOMEWARE\git\test\test_merge&gt;git add a.txt C:\HOMEWARE\git\test\test_merge&gt;git commit -m "add 3 lines, all file unix eol style" [unix c433a63] add 3 lines, all file unix eol style C:\HOMEWARE\git\test\test_merge&gt;git merge windows Auto-merging a.txt CONFLICT (content): Merge conflict in a.txt Automatic merge failed; fix conflicts and then commit the result. C:\HOMEWARE\git\test\test_merge&gt;git ls-files -u 100644 39b4c894078a02afb9b1dfeda6f1127c138e38df 1 a.txt 100644 28b3d018872c08b0696764118b76dd3d0b448fca 2 a.txt 100644 3994da66530b4df80189bb198dcfac9b8f2a7b33 3 a.txt C:\HOMEWARE\git\test\test_merge&gt;git mergetool Merging the files: a.txt Normal merge conflict for 'a.txt': {local}: modified {remote}: modified Hit return to start merge resolution tool (diffmerge): </code></pre> <p>At this point (Hitting "return"), DiffMerge or KDiff3 will open, and you will see for yourself what lines are actually merged, and what lines are ignored.</p> <p><strong>Warning</strong>: the result file will always be in Windows eol mode (CRLF) with DiffMerge...<br> KDiff3 offers to save in one way or another.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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