git merge 中使用 ours theirs

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值