git 为什么git在冲突后输出git状态时说“两者都修改了”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25349227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why git says "both modified" when outputting git status after conflict?
提问by Pascal Precht
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 中合并时在文件上发生冲突时,gitboth modified
在具有冲突的文件上说如下:
$ 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 "bothmodified". Does anybody of you know?
不知道为什么“两者都修改了”。你们有人知道吗?
采纳答案by VonC
This gets back to Git 1.6.5 (Oct. 2009) and commit 4d4d572, which introduced this more detailed message :
这回到 Git 1.6.5(2009 年 10 月)并提交 4d4d572,它引入了以下更详细的消息:
status
: show worktree status of conflicted paths separately
status
: 分别显示冲突路径的工作树状态
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 detailin this new section.
当路径在索引中未合并时,我们过去总是在“已更改但未更新”部分中说“未合并”,即使该路径在工作树中已被删除。
从“更新”部分删除未合并的条目,并创建一个新部分“未合并的路径”。在这个新部分中更详细地描述不同阶段如何冲突。
As you can see in this patch, "both modified" (in both parents) is notthe 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
:
您会在commit 173e6c8 中看到更多案例,其中git status -s
:
For unmerged entries,
X
shows the status of stage #2 (i.e.ours
) andY
shows the status of stage #3 (i.e.theirs
).
对于未合并的条目,
X
显示阶段#2(即ours
)的状态和Y
显示阶段#3(即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?")
这说明了 git 中的索引有3 个阶段的事实(请参阅“如何强制 git 认为文件未合并?”)
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
在具有合并冲突的 Git 文件中,(通常)索引中有三个版本,工作区中有一个带有
diff3 -E
/rcsmerge
冲突标记的版本。
- 索引中的版本是来自共同祖先的第 1 阶段,
- “我们的”版本的第 2 阶段,以及
- “他们的”版本的第 3 阶段。
对于未合并的文件,阶段 0 中没有版本
Here, "both modified" is "modified in 'ours' and 'theirs'.
在这里,“两者都修改”是“在‘我们的’和‘他们的’中进行了修改。