Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why git says "both modified" when outputting git status after conflict?

Tags:

git

When having a conflict on a file while trying to merge in git, git says both modified on the file that has a conflict like this:

$ git status On branch master You have unmerged paths.   (fix conflicts and run "git commit")  Unmerged paths:   (use "git add <file>..." to mark resolution)        both modified: file1  no changes added to commit (use "git add" and/or "git commit -a") 

Not sure why exactly "both modified". Does anybody of you know?

like image 212
Pascal Precht Avatar asked Aug 17 '14 12:08

Pascal Precht


People also ask

What does Git both modified mean?

When having a conflict on a file while trying to merge in git, git says both modified on the file that has a conflict like this: $ git status On branch master You have unmerged paths. ( fix conflicts and run "git commit") Unmerged paths: (use "git add <file>..."

What happens in Git when a conflict occurs between your changes and someone else's?

Git can fail during the merge This occurs because you have committed changes that are in conflict with someone else's committed changes. Git will do its best to merge the files and will leave things for you to resolve manually in the files it lists.


1 Answers

This gets back to Git 1.6.5 (Oct. 2009) and commit 4d4d572, which introduced this more detailed message :

status: show worktree status of conflicted paths separately

When a path is unmerged in the index, we used to always say "unmerged" in the "Changed but not updated" section, even when the path was deleted in the work tree.

Remove unmerged entries from the "Updated" section, and create a new section "Unmerged paths". Describe how the different stages conflict in more detail in this new section.

As you can see in this patch, "both modified" (in both parents) is not the only conflict case.

case 1: how = "both deleted:"; break; case 2: how = "added by us:"; break; case 3: how = "deleted by them:"; break; case 4: how = "added by them:"; break; case 5: how = "deleted by us:"; break; case 6: how = "both added:"; break; case 7: how = "both modified:"; break; 

You see more cases in commit 173e6c8, with git status -s:

For unmerged entries,

  • X shows the status of stage #2 (i.e. ours) and
  • Y shows the status of stage #3 (i.e. theirs).
X          Y     Meaning ------------------------------------------------- D           D    unmerged, both deleted A           U    unmerged, added by us U           D    unmerged, deleted by them U           A    unmerged, added by them D           U    unmerged, deleted by us A           A    unmerged, both added U           U    unmerged, both modified 

That illustrates the fact an index in git has 3 stages (see "How do I force git to think a file is unmerged?")

In Git file that has a merge conflicts has (usually) three versions in index, and a version in working area with diff3 -E / rcsmerge conflict markers.

  • The versions in the index are stage 1 from common ancestor,
  • stage 2 for "our" version, and
  • stage 3 for "theirs" version.

For unmerged file there is no version in stage 0

Here, "both modified" is "modified in 'ours' and 'theirs'.

like image 66
VonC Avatar answered Sep 18 '22 19:09

VonC