2011-02-02 115 views
5

我覺得我接近這一切都是錯誤的。如何在git中合併和更新文件時解決衝突?

我作爲團隊的一部分工作,我們使用git。現在,當我從團隊中提取更新時,顯然存在衝突--git似乎在文件中插入了大量不好的文本。

無論如何,是否有一個體面的方式來管理這些衝突(我在Windows上)。

我用winmerge,但是從我所能看到的,它只能比較2個目錄。它使得解決衝突變得輕而易舉,但要求我在兩個不同的位置有兩個狀態的來源。

有沒有人知道更好的方法來做到這一點或如何將兩者結合?

回答

5

您可以爲每個衝突文件啓動的Git定義mergetool。如果您只有少量衝突,這可以正常工作。一些鏈接:Using Beyond Compare,discussion about this on SO,more general instructionsman page

如果您有很多更改,可以使用一些腳本包。

基本上你需要做的是得到超越比較在Linux中工作:

git config --global merge.conflictstyle=diff3 
git config --global merge.tool=bc3 
git config --global mergetool.bc3.cmd=/usr/bin/bcompare $LOCAL $REMOTE $BASE $MERGED 
git config --global mergetool.bc3.trustexitcode=true 

你可以很容易地找到其他工具的信息,而且Git已經支持幾種工具。

+0

這也不錯:http://blog.wuwon.id.au/2010/09/painless-merge-conflict-resolution-in.html – Ben 2011-02-02 09:00:31

0

這裏的答案一個相關的問題,可能還幫你:

Git on Windows: How do you set up a mergetool?

我親自走了p4merge(免費),用下面的設置(這對我的作品,它可能不是「正確」的方式來做事):

C:\Program Files\Git\cmd

,我有一個文件git-merge.sh它看起來像這樣:

#!/bin/sh 

# Passing the following parameters to mergetool: 
# local base remote merge_result 

base=$1 
alocal=$2 
remote=$3 
result=$4 

if [ -f $base ] 
then 
    p4merge.exe -dl "$base" "$alocal" "$remote" "$result" 
else 
    p4merge.exe -dl "$result" "$alocal" "$remote" "$result" 
fi

C:\Documents and Settings\me.gitconfig包含以下內容:

[merge]  
    keepBackup = false 
    tool = p4merge 
[mergetool "p4merge"] 
    cmd = \"c:/Program Files/Perforce/p4merge.exe\" \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\" 
    keepTemporaries = false 
    trustExitCode = false 
    keepBackup = false 
    path = C:/Program Files/Perforce/p4merge.exe 
[mergetool] 
    keepBackup = false