Git take their or my file while merging

When doing a merge with upstream, git defaults to putting conflict information right into the files. Eg

Here are lines that are either unchanged from the common
ancestor, or cleanly resolved because only one side changed.
<<<<<<< yours:sample.txt
Conflict resolution is hard;
let´s go shopping.
=======
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.

Is there a way to take their or my changes for the whole file without editing it all by hand?

EDIT: I know there are options to git merge and git pull which make the whole merge take one side, but once you started the merge in conflict mode, this is no longer possible. Aside from that I don't want to take ALL changes from one side, but decide manually per file.


Assuming you do not only want to use the command-line

Among others, IntelliJ IDEA or KDiff3 proposes such features. You can accept change for a whole file or do it line-by-line.

If you do want to do it with vanilla git

First list all the differences with the remote branch and then checkout each file separately like this:

git checkout --ours fileIwantToKeep.txt 
git checkout --theirs fileIwantToOverwrite.txt
链接地址: http://www.djcxy.com/p/7572.html

上一篇: 将提交的修订与服务器1进行比较,以获取同一分支

下一篇: Git在合并时采取他们或我的文件