When merging topic branch \"B\" into \"A\" using git merge
, I get some conflicts. I know all the conflicts can be solved using the version in \"B\".
I a
Why doesn't it exist?
While I mention in "git command for making one branch like another" how to simulate git merge -s theirs
, note that Git 2.15 (Q4 2017) is now clearer:
The documentation for '
-X
' for merges was misleadingly written to suggest that "-s theirs
" exists, which is not the case.
See commit c25d98b (25 Sep 2017) by Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit 4da3e23, 28 Sep 2017)
merge-strategies: avoid implying that "
-s theirs
" existsThe description of
-Xours
merge option has a parenthetical note that tells the readers that it is very different from-s ours
, which is correct, but the description of-Xtheirs
that follows it carelessly says "this is the opposite ofours
", giving a false impression that the readers also need to be warned that it is very different from-s theirs
, which in reality does not even exist.
-Xtheirs
is a strategy option applied to recursive strategy. This means that recursive strategy will still merge anything it can, and will only fall back to "theirs
" logic in case of conflicts.
That debate for the pertinence or not of a theirs
merge strategy was brought back recently in this Sept. 2017 thread.
It acknowledges older (2008) threads
In short, the previous discussion can be summarized to "we don't want '
-s theirs
' as it encourages the wrong workflow".
It mentions the alias:
mtheirs = !sh -c 'git merge -s ours --no-commit $1 && git read-tree -m -u $1' -
Yaroslav Halchenko tries to advocate once more for that strategy, but Junio C. Hamano adds:
The reason why ours and theirs are not symmetric is because you are you and not them---the control and ownership of our history and their history is not symmetric.
Once you decide that their history is the mainline, you'd rather want to treat your line of development as a side branch and make a merge in that direction, i.e. the first parent of the resulting merge is a commit on their history and the second parent is the last bad one of your history. So you would end up using "
checkout their-history && merge -s ours your-history
" to keep the first-parenthood sensible.And at that point, use of "
-s ours
" is no longer a workaround for lack of "-s theirs
".
It is a proper part of the desired semantics, i.e. from the point of view of the surviving canonical history line, you want to preserve what it did, nullifying what the other line of history did.
Junio adds, as commented by Mike Beaton:
git merge -s ours
effectively says 'mark commits made up toon their branch as commits to be permanently ignored';
and this matters because, if you subsequently merge from later states of their branch, their later changes will be brought in without the ignored changes ever being brought in.