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

你可能感兴趣的:(Git - ours vs theirs)