You're going to pull some changes, but oops, you're not up to date:

> git fetch origin
> git pull origin master
From ssh://gitosis@example.com:22/projectname
 * branch            master     -> FETCH_HEAD
Updating a030c3a..ee25213
error: Entry 'filename.c' not uptodate. Cannot merge.

So you get up-to-date and try again, but have a conflict:

> git add filename.c
> git commit -m "made some wild and crazy changes"
From ssh://gitosis@example.com:22/projectname
 * branch            master     -> FETCH_HEAD
Auto-merging filename.c
CONFLICT (content): Merge conflict in filename.c
Automatic merge failed; fix conflicts and then commit the result.

So you decide to take a look at the changes:

> git mergetool

Oh me, oh my, upstream changed some things, but just to use my changes.... no... their changes...

> git checkout --ours filename.c
> git checkout --theirs filename.c
> git add filename.c
> git commit -m "using theirs"

And then we try a final time

> git pull origin master
From ssh://gitosis@example.com:22/projectname
 * branch            master     -> FETCH_HEAD
Already up-to-date.

Ta-da!

share | improve this answer


4  
This was super helpful because I had a lot of merge errors with binary files (art assets) and merging those seems to always fail, so I need to overwrite it with the new file always and not "merge" –  petrocket  Jun 8 '11 at 17:39
74  
Thanks! 'git checkout --theirs' vs 'git checkout --ours' was exactly the information that I was looking for, and isn't mentioned in the Git book on merge resolution. –  swestrup  Jul 1 '11 at 21:19
1  
+1 This is most likely what the OP was looking for. It certainly was exactly what I needed. You rock! –  jlafay Jul 8 '11 at 21:31
3  
--ours and --theirs is HARD to find in the docs. Thank you for that –  Slomojo  May 11 '12 at 5:18
6  
Careful! The meaning of --ours and --theirs is reversed. --ours == the remote. --theirs == local. See git merge --help –  mmell  Mar 4 at 22:56

原文:http://stackoverflow.com/questions/161813/how-do-i-fix-merge-conflicts-in-git?rq=1


Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐