Choose Git merge strategy for specific files (“ours”, “mine”, “theirs”)

后端 未结 3 1997
感情败类
感情败类 2020-11-29 15:00

I am in the middle of rebasing after a git pull --rebase. I have a few files that have merge conflicts. How can I accept \"their\" changes or \"my\" changes f

3条回答
  •  情歌与酒
    2020-11-29 15:57

    Even though this question is answered, providing an example as to what "theirs" and "ours" means in the case of git rebase vs merge. See this link

    Git Rebase
    theirs is actually the current branch in the case of rebase. So the below set of commands are actually accepting your current branch changes over the remote branch.

    # see current branch
    $ git branch
    ... 
    * branch-a
    # rebase preferring current branch changes during conflicts
    $ git rebase -X theirs branch-b
    

    Git Merge
    For merge, the meaning of theirs and ours is reversed. So, to get the same effect during a merge, i.e., keep your current branch changes (ours) over the remote branch being merged (theirs).

    # assuming branch-a is our current version
    $ git merge -X ours branch-b  # <- ours: branch-a, theirs: branch-b
    

提交回复
热议问题