Why git shows a merge conflict when the HEAD version has no content at the line
Asked Answered
G

1

5

I'm trying to do a git merge master from another branch, then I got this conflict:

<<<<<<< HEAD
=======
    t.text     "label_en"
    t.text     "help_text_en"
    t.text     "options_en"
>>>>>>> master

I know how to resolve the conflict, but I'm curious why does git recognize this as a conflict in the first place since the HEAD version has no content on the specific line.

<<<<<<< HEAD
=======

Isn't a simple case for git to just add the 3 lines from the master and merge it?


Update:

@Marcin is correct. Based on the answer, I did a test, let's say I have a git tree like below:

 A ---- B  (master)
      \
        C  (another branch)

content of temp.txt in commit A:

    t.text    "LALALA"

content of temp.txt in commit B:

    t.text    "label_en"
    t.text    "help_text_en"
    t.text    "options_en"

content of temp.txt in commit C is empty.


At this point, if I do:

git checkout another_branch
git merge master

Then I will get the following:

<<<<<<< HEAD
=======
    t.text     "label_en"
    t.text     "help_text_en"
    t.text     "options_en"
>>>>>>> master
Gnosis answered 4/4, 2013 at 8:5 Comment(1)
To me similar happened when I clearly only added, nothing removed. git diff origin/main was also showing all added.Abhorrence
L
7

You made a change on that line on master and another branch, something was removed from that line on the latter and git isn't able to resolve that conflict automagically.

Lengthy answered 4/4, 2013 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.