Reputation: 670
I have two branches version-1.0
and version-2.0
, their common ancestor is commit C
.
I try to merge the two branch and it shows a file a.txt
conflicted.
for example:
$ git checkout version-2.0
$ git merge version-1.0
$ git status
Unmerged paths:
(use "git add/rm <file>..." as appropriate to mark resolution)
deleted by them: a.txt
$ git ls-files -u | grep a.txt
100644 xxxxxxxxxxxxxxxxxx 1 a.txt
100644 yyyyyyyyyyyyyyyyyy 2 a.txt
$ git --version # The git enviroment
git version 2.34.1.windows.1
I get common ancestor commit C
from this command: git merge-base version-1.0 version-2.0
.
But git diff --stat C version-1.0
didn't show any change of a.txt
file.
How does Git make this file conflicted?
How to get more details when Git Merge two branch?
Thanks for your answer!
Upvotes: 0
Views: 853
Reputation: 535945
The git status
output you provide is exactly what you may expect to see when one side of an attempted merge deletes a file but the other side edits the same file.
I'll give a toy example. We start with this situation:
* e9f73e4 (mybranch) deleted C
| * fb8c1ca (HEAD -> main) edited C
|/
* c54f4a6 C
* 0e1d397 B
* 38615b3 A
We are on main
. We attempt to merge mybranch
, and we get a merge conflict, with exactly the status you provided:
% git switch main
% git merge mybranch
% git status
On branch main
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add/rm <file>..." as appropriate to mark resolution)
deleted by them: C
no changes added to commit (use "git add" and/or "git commit -a")
To see what happened, compare the merge-base to "them" (mybranch
), using the compact-summary
option to give a nice clear output:
% git diff --compact-summary $(git merge-base main mybranch) mybranch
C (gone) | 1 -
1 file changed, 1 deletion(-)
To resolve the conflict, either git add
or git rm
the affected file, and then say git merge --continue
. Let's say I agree with "them":
% git rm C
rm 'C'
% git merge --continue
[main d19f36b] Merge branch 'mybranch'
The merge succeeds and life goes on.
Upvotes: 1