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 am aware of git merge -s ours
. But what I want is something like git merge -s theirs
.
Why doesn't it exist? How can I achieve the same result after the conflicting merge with existing git
commands? (git checkout
every unmerged file from B)
The "solution" of just discarding anything from branch A (the merge commit point to B version of the tree) is not what I am looking for.
git merge -s ours. The ours strategy is simple: it discards all changes from the other branch. This leaves the content on your branch unchanged, and when you next merge from the other branch, Git will only consider changes made from this point forward.
Git merging combines sequences of commits into one unified history of commits. There are two main ways Git will merge: Fast Forward and Three way. Git can automatically merge commits unless there are changes that conflict in both commit sequences.
The git pull command first runs git fetch which downloads content from the specified remote repository. Then a git merge is executed to merge the remote content refs and heads into a new local merge commit.
A similar alternative is the --strategy-option
(short form -X
) option, which accepts theirs
. For example:
git checkout branchA git merge -X theirs branchB
However, this is more equivalent to -X ours
than -s ours
. The key difference being that -X
performs a regular recursive merge, resolving any conflicts using the chosen side, whereas -s ours
changes the merge to just completely ignore the other side.
In some cases, the main problem using -X theirs
instead of the hypothetical -s theirs
is deleted files. In this case, just run git rm
with the name of any files that were deleted:
git rm {DELETED-FILE-NAME}
After that, the -X theirs
may work as expected.
Of course, doing the actual removal with the git rm
command will prevent the conflict from happening in the first place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With