Why would one use “git merge -s ours”?

前端 未结 6 1803
無奈伤痛
無奈伤痛 2021-02-02 13:46

I understand that the \"ours\" merge strategy (hear the quotes around merge?) actually does not use any commits from the other branch.

The \"ours\" strategy is

6条回答
  •  醉话见心
    2021-02-02 14:24

    In short: common ancestor.

    Detail

    Whenever you do a merge, git will find a common ancestor of the current branch and the branch to be merged. Then git merges commits after the common ancestor from the other branch into current branch.

    git merge -s ours ignores any content from the other branch entirely. It's just creating a new common ancestor.

    It changes the commit range to be merged for the future merges.

    Here's a use case in the "Advanced Merging" chapter from the book Pro Git

    For example, say you branched off a release branch and have done some work on it that you will want to merge back into your master branch at some point. In the meantime some bugfix on master needs to be backported into your release branch. You can merge the bugfix branch into the release branch and also merge -s ours the same branch into your master branch (even though the fix is already there) so when you later merge the release branch again, there are no conflicts from the bugfix.

    In this example, git merge -s ours is used to skip commits related to bugfix commits merged in release branch.

提交回复
热议问题