How to resolve conflicts while merging and updating files in git?
I feel I am approaching this all wrong.
I work as part of team and we use git. Now, when I pull updates from my team there are obviously conflicts from time to time - git seems to开发者_C百科 insert loads of text in the files which isn't good.
Anyway, is there a decent way to manage these conflicts (I'm on windows).
I used winmerge, but from what I can see, It can only compare 2 directories. It makes resolving conflicts a breeze, but requires me to have 2 states of the source in 2 different locations.
Does anybody know a better way to do this or how to integrate the two?
You can define a mergetool for Git which gets launced for each conflicting file. This works fine if you only have a small number of conflicts. Some links: Using Beyond Compare, discussion about this on SO, more general instructionsand the man page.
There are some script packages that can be used if you have lots of changes.
Basically what you need to do is to get e.g. Beyond Compare to work in 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
You can find info on other tools easily, and Git already has support for several tools.
Here's a related question with answers that might also help you:
Git on Windows: How do you set up a mergetool?
I've personally gone for p4merge (free), with the following setup (which works for me, it might not be the 'right' way to do things):
in C:\Program Files\Git\cmd
, I have a file git-merge.sh
which looks like this:
#!/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
In C:\Documents and Settings\me
my .gitconfig
contains the following section:
[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
精彩评论