{"thread":{"id":"61343","subject":"Why conflict when merge a branch that the directory is unmodified","startedAt":"2024-04-20T03:09:02Z","lastAt":"2024-04-23T08:10:19Z","messageCount":2,"participants":["wuzhouhui14","Konstantin Khomoutov"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"493245","messageId":"tencent_6FF9636AA4D83460C0CE7C9F1EEC3463CF05@qq.com","threadId":"61343","inReplyTo":null,"subject":"Why conflict when merge a branch that the directory is unmodified","fromName":"wuzhouhui14","fromEmail":"wuzhouhui14@foxmail.com","sentAt":"2024-04-20T03:00:45Z","receivedAt":"2024-04-20T03:09:02Z","isPatch":false,"sender":{"key":"wuzhouhui14@foxmail.com","avatar":null},"body":"Hi,\n\nSuppose I have two branches with following commit histories:\n\nB----C---D(directory abc/ modified)               Branch1\n    /\nL--M---O(directory abc/ not modified)            Branch2\n\nIn previous graph, the Branch1 merge Branch2 in commit C. After commit C,\nthe Branch1 modified some contents in director abc/. Branch2 doesn't\nmodify directory abc/ since commit M, which has been merged into Branch1.\n\nThen, when I do:\n\n  git checkout Branch1\n  git merge Branch2\n\nthe director abc/ contains conflicts, why? Because the director abc/ doesn't\nchanged since commit M in Branch2, so directory abc/ should not have\nconflicts.\n\nThanks."},{"id":"493355","messageId":"20240423072622.hctxuaomw3cmivhu@carbon","threadId":"61343","inReplyTo":"tencent_6FF9636AA4D83460C0CE7C9F1EEC3463CF05@qq.com","subject":"Re: Why conflict when merge a branch that the directory is unmodified","fromName":"Konstantin Khomoutov","fromEmail":"kostix@bswap.ru","sentAt":"2024-04-23T07:26:22Z","receivedAt":"2024-04-23T08:10:19Z","isPatch":false,"sender":{"key":"kostix@bswap.ru","avatar":null},"body":"On Sat, Apr 20, 2024 at 11:00:45AM +0800, wuzhouhui14 wrote:\n\n> Suppose I have two branches with following commit histories:\n> \n> B----C---D(directory abc/ modified)               Branch1\n>     /\n> L--M---O(directory abc/ not modified)            Branch2\n> \n> In previous graph, the Branch1 merge Branch2 in commit C. After commit C,\n> the Branch1 modified some contents in director abc/. Branch2 doesn't\n> modify directory abc/ since commit M, which has been merged into Branch1.\n> \n> Then, when I do:\n> \n>   git checkout Branch1\n>   git merge Branch2\n> \n> the director abc/ contains conflicts, why? Because the director abc/ doesn't\n> changed since commit M in Branch2, so directory abc/ should not have\n> conflicts.\n\nThere should not be any conflict (and FWIW I've just verified there is not\nusing a simple test repository).\n\nI can suggest three reasons (while probably there could be more):\n\n - The contents of abc has been changed in M; in other words, abc as recorded\n   in M is different from its state in C.\n\n - The files in abc as recorded in D and O have difference in line endings -\n   such as on one branch they have LFs and on the other - CRLFs.\n\n - The graph in a real repository you're dealing with is more complicated\n   than presented in your picture, and there exist commits between\n   M and O - and may be between C and D as well - which have changed the\n   state of abc, but you just failed to spot these modifications during\n   your analysis.\n\nHere's a graph from my sample repository where I tried to model your\nsituation:\n\n-------------------------------- 8< --------------------------------\n$ git log --graph\n*   commit 7fc08ef95934a404021b46f46df3250340b5122f\n|\\  Merge: 2a72a51 2c8ef4f\n| | Author: user <user@acme.com>\n| | Date:   Tue Apr 23 10:14:31 2024 +0300\n| | \n| |     Merge branch 'branch1' into branch2\n| | \n| * commit 2c8ef4f49bf2a9900c009a04943422a66b2987c6 - on branch1\n| | Author: user <user@acme.com>\n| | Date:   Tue Apr 23 10:14:16 2024 +0300\n| | \n| |     modify bar.txt\n| |   \n| *   commit 001a394ef8d31785362241ef63ca422dad496b39 - M in your case\n| |\\  Merge: b072e1e e8af26d\n| | | Author: user <user@acme.com>\n| | | Date:   Tue Apr 23 10:13:11 2024 +0300\n| | | \n| | |     Merge branch 'branch2' into branch1\n| | | \n| * | commit b072e1e86f7db47286bc08a435c71486c0ca4f77 - on branch 1\n| | | Author: user <user@acme.com>\n| | | Date:   Tue Apr 23 10:12:58 2024 +0300\n| | | \n| | |     add bar.txt\n| | | \n* | | commit 2a72a51b2aea87f6ed13013865eb181551eba31f - on branch2, like C\n| |/  Author: user <user@acme.com>\n|/|   Date:   Tue Apr 23 10:13:47 2024 +0300\n| |   \n| |       modify abc/foo.txt again\n| | \n* | commit e8af26def1078e0293c46a22db3ad788fd6f38be - on branch2\n| | Author: user <user@acme.com>\n| | Date:   Tue Apr 23 10:12:08 2024 +0300\n| | \n| |     modify abc/foo.txt\n| | \n* | commit c7c0b344e943c9d548447886a50fa618e0c7f107 - branch2 is born\n|/  Author: user <user@acme.com>\n|   Date:   Tue Apr 23 10:11:42 2024 +0300\n|   \n|       add abc/foo.txt\n| \n* commit 192905a78af1645603f54751ae7139d1aca22a80\n  Author: user <user@acme.com>\n  Date:   Tue Apr 23 10:10:56 2024 +0300\n  \n      root commit\n-------------------------------- 8< --------------------------------\n\n"}]}