2

Steps to reproduce the situation 1. Create file test.txt in your git master with content

A
B
C

and commit it.

  1. Create new branch test-v1
  2. In master branch remove line B, so you have just

    A
    C
    
  3. Cherry-pick commit from step 3 to test-v1

  4. Checkout branch test-v1 and add B line again and commit

    A
    B
    C
    
  5. Checkout master branch

  6. git merge test-v1

What I expected to get:

    A
    B
    C

What I got:

    A
    C

Question: Why is B auto-resolved and not marked as merge conflict when merging?

I tried different merge strategies (git merge --strategy), but I did not find any where I would get the expected result. The only way was to git rebase test-v1 on master. But I suppose in more complicated setup, it could rewrite history of master, right?

LukasT
  • 441
  • 4
  • 15

1 Answers1

2

As we already discussed in the git IRC and with big help of thiago, which is a registered user on Freenode and a experienced git user, I'll take his answer and put it here for completeness:

At the point you branched off 'test-v1' the file test.txt does have the content

A
B
C

in both branches, master and test-v1.

Now you are applying changes in master to test.txt and cherry-pick them to branch test-v1. After that you checked out test-v1 and added the B back to the file. What will happen now when you merge? Imagine I am git now:

  1. Ok let me look up the common ancestor: Ahh ok I got it, file test looks like A B C

  2. Lets look for the changes made in test-v1: Hmm ok looks equal to the common ancestor

  3. Lets look for the changes made in master: Ahh ok, something changed, lets take the modifaction into account

-> Result

A
C
ckruczek
  • 2,361
  • 2
  • 20
  • 23