SORU
14 Mayıs 2009, PERŞEMBE


Git-birleştirme için mümkün hat-sonu farkları görmezden gelmek mi?

git merge satır-sonu farkları göz ardı etmek mümkün müdür?

Belki de yanlış soruyu soruyorsun ... ama ben hazırım

config.crlf input ama ortalık biraz dağınık ve kontrolden çıktı, özel olarak bulunduğumda uisng çalıştımaslında sonra.

Bir kere, aslında sonra bu config uygulayarak bu seçeneği uygulamadan önce depoya teslim dosyaları etkileyecek gibi görünmüyor. Başka bir şey birden şimdi CRLF LF dönüştürülen hakkında can sıkıcı uyarı iletileri bir sürü neden tamamlar.

Dürüst olmak gerekirse, gerçekten çizgi-bitiş kullanılır, ben şahsen Unıx tarzı \n ama ne olursa olsun tercih ne olduğu umurumda değil. Umurumda olan tek şey, git merge biraz daha akıllı ve Satır sonları farklılıklar göz ardı edilebilir.

Bazen iki özdeş dosyalar var, ama git çatışma olarak işaretleyin (ve çatışmatümdosya) farklı bir çizgi karakter son kullandıkları için yeterlidir.

Güncelleme:

git diff --ignore-space-at-eol bir seçeneği kabul ettiğini öğrendim, git merge Bu seçenek de kullanmasına izin vermek mümkün mü?

CEVAP
14 Mayıs 2009, PERŞEMBE


Güncelleme 2013:

Daha yeni sürümleri gıt yetki kullanma stratejisi ile recursive ve strateji birleştirinseçeneği(-X):

git merge -s recursive -Xignore-space-at-eol

Ama kullanma "-Xignore-space-change" is also a possibility

  • Fab-V belowsöz:
    git merge master -s recursive -X renormalize
    
    

jakub.g also comments that the strategies work also with cherry-picking:

git cherry-pick abcd123456 --strategy=recursive --strategy-option=renormalize 

This works much better than ignore-all-space.


Original answer (May 2009)

The patch for ignoring eol style has been proposed in June 2007, but it only concerns git diff --ignore-space-at-eol, not git merge.

At the time, the question has been askeed:

Should --ignore-space-at-eol be an option to git-merge ?
Merges are where this functionality matters.
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 ?

Julio C Hamano was not exactly enthusiastic:

This certainly is tempting, but I suspect that should be left to later rounds.
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.
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.

The general idea, when it comes to git merge, is to rely on the third-party merge tool.

For instance, I have setup DiffMerge to be the tool for Git merge, setting a ruleset which allow that merge tool to ignore eol for certain type of files.


Setup on Windows, with MSysGit1.6.3, either for DOS or Git bash session, with DiffMerge or KDiff3:

  • set a directory into your PATH (here: c:\HOMEWARE\cmd).
  • add in that directory the script merge.sh (wrapper for your favorite merge tool)

merge.sh:

#!/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
  • Declare your merge wrapper for Git

Git config commands:

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
  • Check that autoCRLF is false

git config at system level:

git config ---system core.autoCRLF=false
  • Test that, when two lines are identical (but their eol chars), both DiffMerge or KDiff3 will ignore those line during a merge.

DOS script (note: the dos2unix command comes from here, and is used to simulate a Unix eol-style. That command has been copied in the directory mentioned at the beginning of this answer.):

C:\HOMEWARE\git\test>mkdir test_merge C:\HOMEWARE\git\test>cd test_merge C:\HOMEWARE\git\test\test_merge>git init C:\HOMEWARE\git\test\test_merge>echo a1 > a.txt & echo a2 >> a.txt C:\HOMEWARE\git\test\test_merge>git add a.txt C:\HOMEWARE\git\test\test_merge>git commit -m "a.txt, windows eol style" C:\HOMEWARE\git\test\test_merge>git checkout -b windows Switched to a new branch 'windows' C:\HOMEWARE\git\test\test_merge>echo a3 >> a.txt & echo a4 >> a.txt C:\HOMEWARE\git\test\test_merge>git add a.txt C:\HOMEWARE\git\test\test_merge>git commit -m "add two lines, windows eol style" C:\HOMEWARE\git\test\test_merge>git checkout master C:\HOMEWARE\git\test\test_merge>git checkout -b unix Switched to a new branch 'unix' C:\HOMEWARE\git\test\test_merge>echo au3 >> a.txt & echo au4 >> a.txt && echo au5 >> a.txt C:\HOMEWARE\git\test\test_merge>dos2unix a.txt Dos2Unix: Processing file a.txt ... C:\HOMEWARE\git\test\test_merge>git add a.txt C:\HOMEWARE\git\test\test_merge>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>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>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>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):

Bu noktada (İsabet "") dönüş, DiffMerge veya KDiff3 açılacak ve çizgileri tam olarak birleştirilmiş ve çizgiler dikkate alınmaz kendiniz için göreceksiniz.

Uyarı: sonuç dosya her zaman Windows eol modu (CRLF) DiffMerge ile olacak...
KDiff3 bir şekilde kaydetmek için sunmaktadır.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Matthew Morrill

    Matthew Morr

    15 EKİM 2011
  • maxman.tv

    maxman.tv

    29 EKİM 2013
  • newport83

    newport83

    19 HAZİRAN 2006