Video in progress
Are `git merge -s ours` and `git merge -X ours` the same thing? Which one do you use and when?
No. -s ours is a separate strategy: it discards all the changes from the other branch and only writes a merge commit. -X ours is an option of the ordinary ort merge: all changes are taken, and only in the hunks that conflict is your side chosen.
📖 Answer
The names are almost the same, and the results are completely different.
git merge -s ours release/2.3
# the code does not change, but the history marks release/2.3 as "merged"
git merge -X ours feature/pricing
# the non-conflicting changes from the feature come in,
# and where there are conflicts the current branch's version stays
When -s ours is needed: the fixes from an old release branch have already gone into main another way (by hand, written differently), but Git must not try to bring them again later. After the merge commit, git branch --merged also gives the right result. There is no strategy called -s theirs, only the -X theirs option.
The dangerous part of -X ours/-X theirs is that it works silently. For example, both sides changed one method: Git takes your version, but a new call the other side added to that method stays elsewhere (with no conflict). The result compiles, but the logic is a mix. That is why tests are mandatory afterwards.
One more trap in rebase: there, ours is the base you are putting your commits on top of. git rebase -X theirs origin/main keeps your commits' version in conflicts.
Sign up to mark studied questions and save your progress.