Git merge with force overwrite

前端 未结 6 716
悲哀的现实
悲哀的现实 2021-01-29 19:03

I have a branch called demo which I need to merge with master branch. I can get the desired result with following commands:

git pull or         


        
6条回答
  •  星月不相逢
    2021-01-29 19:54

    I had a similar issue, where I needed to effectively replace any file that had changes / conflicts with a different branch.

    The solution I found was to use git merge -s ours branch.

    Note that the option is -s and not -X. -s denotes the use of ours as a top level merge strategy, -X would be applying the ours option to the recursive merge strategy, which is not what I (or we) want in this case.

    Steps, where oldbranch is the branch you want to overwrite with newbranch.

    • git checkout newbranch checks out the branch you want to keep
    • git merge -s ours oldbranch merges in the old branch, but keeps all of our files.
    • git checkout oldbranch checks out the branch that you want to overwrite
    • get merge newbranch merges in the new branch, overwriting the old branch

提交回复
热议问题