Merging selective lines of code using Git?
I would like to force git to always merge using a (kind of) 3-way conflicts resolutio开发者_开发问答n. Moreover, I want to do it to the point of being able to choose single lines.
At the moment I am merging two branches. However, if possible, I'd like to know how to perform this task even when merging multiple branches.
Git tries to do 3-way merging by default (the recursive
strategy for 2 heads, and the octopus
strategy for 3+ heads).
If you want to see 3-way resolution options when manually merging, try setting the merge.conflictstyle
config option to diff3
.
(See the Configuration section of the git-merge
man page for details on that option.)
The blog post "Five advanced Git merge techniques" does give even more details on the diff3 setting:
Turn diff3 conflicts using
git config --global merge.conflictstyle diff3
.
The diff3 conflict style adds an extra section between the new|||||||
marker and=======
markers, which indicates:
- the original contents of the section,
- with your changes above and
- their (the branch that is being merged in's) changes below.
Even without a diff tool, the command git show
can help:
When you are inside a merge, you can use a special
:N:
syntax, whereN
is a number, to automatically select one of the merge parents.
1
selects the common base commit (the lower revision),2
selects your version ("mine
"), and3
selects their version (the higher revision).
So
git show :3:foobar.txt
shows the upstream version offoobar.txt
.
精彩评论