0

I don't understand in what condition do git consider there are conflicts when merging two local branches.

When I create a file a.py in branch test1, then merge it to another branch test2, and then make some modifications, the merge process seems all smooth and do not report conflicts.

But when I create a file a.py in branch test1 and create another file with the same name a.py in branch test2. Every time I try to merge two files, git report me a conflict.

Second day using git, I just don't know how merge works, chatGPT told me that when one file in two branch is modified differently at same lines. But what make me confused are:

  1. in my case, I only delete one line, the git diff output is :

    diff --git a/c.py b/c.py
    index f2db9da..b917a72 100644
    --- a/c.py
    +++ b/c.py
    @@ -1,2 +1 @@
     print(1)
    -print(2)
    

2. If all content are to be compared line by line, then when I type a break line in the middle of a file, then the rest of the file will no longer be recognized as the same as other branches since the lines are all shifted. So what's the point doing such overly rigorous check?

3. Or if git can think like "he just added one break line so let's just sync that to another branch". And how could git be able to do this? Suppose it can actually do this, when I delete from the middle of the file to the end and then paste it back, does git think I delete and add something? or it just think nothing really happened. If the second one, then it seems still do the line-comparing, and then this question just turn back to my no.2 question. If the first one, the conflict are just more serious because half of the file need to review manually, though they are identical.

If I'm wrong, I really apologize for that, because I just learned the basic git usage yesterday, and stuck in the merge stuff. I would appreciate that if you can elaborate the situation for me, thank you guys so much!

4
  • Yes, during merging Git inspects both sides line-by-line and compares what has changed on each side and whether the changes "can be synced" (using a fairly intuitive, but unsophisticated, definition of that term) automatically. Commented Sep 11, 2023 at 5:33
  • Only when Git finds that the two sides made textual changes in overlapping regions in different ways, then a conflict occurs. For example, when one side changed print(1) to print(3) and the other side removed the line print(1), that would be a conflict. Commented Sep 11, 2023 at 5:36
  • 3
    chatGPT told me. All such machine generated response systems are notorious serial liers. It represents absolutely no authority whatsoever and its replies should be regarded with the highest degree of scepticism. Only use it as input to what to search for with normal web search engines. Commented Sep 11, 2023 at 7:25
  • @hlovdal, I disagree. The body of text written on git, merges, etc... make the training set of LLMs on this topic very rich. This translates into highly accurate generated text. A tool like GPT is an ideal first stop for researching basic questions like "what is a merge", "what is a merge conflict", etc. An LLM may be less proficient at answering nuanced questions regarding topics of opinion, or at questions that are highly novel and technical, but the topic at hand is not that. I was going to recommend interrogating ChatGPT more, and also googling the basics before asking questions. Commented Sep 15, 2023 at 17:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.