From: Konstantin Khomoutov <kostix@bswap.ru>
To: wuzhouhui14 <wuzhouhui14@foxmail.com>
Cc: git <git@vger.kernel.org>
Subject: Re: Why conflict when merge a branch that the directory is unmodified
Date: Tue, 23 Apr 2024 10:26:22 +0300 [thread overview]
Message-ID: <20240423072622.hctxuaomw3cmivhu@carbon> (raw)
In-Reply-To: <tencent_6FF9636AA4D83460C0CE7C9F1EEC3463CF05@qq.com>
On Sat, Apr 20, 2024 at 11:00:45AM +0800, wuzhouhui14 wrote:
> Suppose I have two branches with following commit histories:
>
> B----C---D(directory abc/ modified) Branch1
> /
> L--M---O(directory abc/ not modified) Branch2
>
> In previous graph, the Branch1 merge Branch2 in commit C. After commit C,
> the Branch1 modified some contents in director abc/. Branch2 doesn't
> modify directory abc/ since commit M, which has been merged into Branch1.
>
> Then, when I do:
>
> git checkout Branch1
> git merge Branch2
>
> the director abc/ contains conflicts, why? Because the director abc/ doesn't
> changed since commit M in Branch2, so directory abc/ should not have
> conflicts.
There should not be any conflict (and FWIW I've just verified there is not
using a simple test repository).
I can suggest three reasons (while probably there could be more):
- The contents of abc has been changed in M; in other words, abc as recorded
in M is different from its state in C.
- The files in abc as recorded in D and O have difference in line endings -
such as on one branch they have LFs and on the other - CRLFs.
- The graph in a real repository you're dealing with is more complicated
than presented in your picture, and there exist commits between
M and O - and may be between C and D as well - which have changed the
state of abc, but you just failed to spot these modifications during
your analysis.
Here's a graph from my sample repository where I tried to model your
situation:
-------------------------------- 8< --------------------------------
$ git log --graph
* commit 7fc08ef95934a404021b46f46df3250340b5122f
|\ Merge: 2a72a51 2c8ef4f
| | Author: user <user@acme.com>
| | Date: Tue Apr 23 10:14:31 2024 +0300
| |
| | Merge branch 'branch1' into branch2
| |
| * commit 2c8ef4f49bf2a9900c009a04943422a66b2987c6 - on branch1
| | Author: user <user@acme.com>
| | Date: Tue Apr 23 10:14:16 2024 +0300
| |
| | modify bar.txt
| |
| * commit 001a394ef8d31785362241ef63ca422dad496b39 - M in your case
| |\ Merge: b072e1e e8af26d
| | | Author: user <user@acme.com>
| | | Date: Tue Apr 23 10:13:11 2024 +0300
| | |
| | | Merge branch 'branch2' into branch1
| | |
| * | commit b072e1e86f7db47286bc08a435c71486c0ca4f77 - on branch 1
| | | Author: user <user@acme.com>
| | | Date: Tue Apr 23 10:12:58 2024 +0300
| | |
| | | add bar.txt
| | |
* | | commit 2a72a51b2aea87f6ed13013865eb181551eba31f - on branch2, like C
| |/ Author: user <user@acme.com>
|/| Date: Tue Apr 23 10:13:47 2024 +0300
| |
| | modify abc/foo.txt again
| |
* | commit e8af26def1078e0293c46a22db3ad788fd6f38be - on branch2
| | Author: user <user@acme.com>
| | Date: Tue Apr 23 10:12:08 2024 +0300
| |
| | modify abc/foo.txt
| |
* | commit c7c0b344e943c9d548447886a50fa618e0c7f107 - branch2 is born
|/ Author: user <user@acme.com>
| Date: Tue Apr 23 10:11:42 2024 +0300
|
| add abc/foo.txt
|
* commit 192905a78af1645603f54751ae7139d1aca22a80
Author: user <user@acme.com>
Date: Tue Apr 23 10:10:56 2024 +0300
root commit
-------------------------------- 8< --------------------------------
prev parent reply other threads:[~2024-04-23 8:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-20 3:00 Why conflict when merge a branch that the directory is unmodified wuzhouhui14
2024-04-23 7:26 ` Konstantin Khomoutov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240423072622.hctxuaomw3cmivhu@carbon \
--to=kostix@bswap.ru \
--cc=git@vger.kernel.org \
--cc=wuzhouhui14@foxmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).