Is there a “theirs” version of “git merge -s ours”?

前端 未结 18 1530
傲寒
傲寒 2020-11-22 06:42

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

18条回答
  •  花落未央
    2020-11-22 06:59

    I just recently needed to do this for two separate repositories that share a common history. I started with:

    • Org/repository1 master
    • Org/repository2 master

    I wanted all the changes from repository2 master to be applied to repository1 master, accepting all changes that repository2 would make. In git's terms, this should be a strategy called -s theirs BUT it does not exist. Be careful because -X theirs is named like it would be what you want, but it is NOT the same (it even says so in the man page).

    The way I solved this was to go to repository2 and make a new branch repo1-merge. In that branch, I ran git pull git@gitlab.com:Org/repository1 -s ours and it merges fine with no issues. I then push it to the remote.

    Then I go back to repository1 and make a new branch repo2-merge. In that branch, I run git pull git@gitlab.com:Org/repository2 repo1-merge which will complete with issues.

    Finally, you would either need to issue a merge request in repository1 to make it the new master, or just keep it as a branch.

提交回复
热议问题