After a Git merge conflict, a lot of files I didn't touch become changes to be committed

前端 未结 6 1371
忘掉有多难
忘掉有多难 2020-12-05 09:47

So I\'m working in a branch, make some changes, and run git merge master. I get a merge conflict on one of the files I modified (which I know how to deal with),

6条回答
  •  旧巷少年郎
    2020-12-05 10:25

    Where I find this pop up is if I:

    1) create, and work on a branch (b1)

    ---m
        \
         b1
    
    ---m
        \
          ---b1
    

    2) create a new branch (b2) from b1, during which time someone else makes changes to completely unrelated code in master

    ----------------m
        \
          ---b1
              \
               b2
    

    3) go back and make some changes to b1, and then pull b1 into master.

    ----------------m
        \          /
          -------b1
              \
                --b2
    

    If I then try to pull from master into b2, I'll get a conflict because of the changes made to b1 after creating b2. If I fix the conflict, the resulting commit will include all changes that have occurred on master since the branch of b1, as if I had performed them. (git blame seems to be able to tell the original author though)

    In this scenario, if I instead first pull from b1 into b2, and sort out the merge there, then I can then pull from master without issue, and the pulled-in irrelevant commits won't show up as changes I've made.

    git merge --abort is your friend, if you're in the middle of a merge full of commits you didn't make.

提交回复
热议问题