Git - ours vs theirs

转自: https://nitaym.github.io/ourstheirs/

Git Merging

Let's merge conflicting branch feature into master

$ git checkout master
$ git merge feature
Auto-merging Document
CONFLICT (content): Merge conflict in codefile.js
Automatic merge failed; fix conflicts and then commit the result.

either fix the conflict manually by editing codefile.js, or use

# to select the changes done in master
$ git checkout --ours codefile.

# to select the changes done in feature
$ git checkout --theirs codefile.js

then, continue as you would normally merge

$ git add codefile.js
$ git merge --continue
[master 5d01884] Merge branch 'feature'
Git Rebasing

let's rebase conflicting branch feature over master

$ git checkout feature
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: a commit done in branch feature
error: Failed to merge in the changes.
...

either fix the conflict manually by editing codefile.js, or use

# to select the changes done in master
$ git checkout --ours codefile.js

# to select the changes done in feature
$ git checkout --theirs codefile.js

then, continue as you would normally do

$ git add codefile.js
$ git rebase --continue
Applying: a commit done in branch feature
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容