gpt4 book ai didi

git - 为什么git在冲突后输出git状态时说 "both modified"?

转载 作者:IT王子 更新时间:2023-10-29 01:04:53 32 4
gpt4 key购买 nike

当尝试在 git 中 merge 时文件发生冲突时,git 会在有冲突的文件上显示 both 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")

不确定为什么“已修改”。你们有人知道吗?

最佳答案

这可以追溯到 Git 1.6.5(2009 年 10 月)和 commit 4d4d572 ,其中介绍了这条更详细的消息:

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 detail in this new section.

如您在此补丁中所见,“两者都修改”(在 parent 双方中)不是唯一的冲突情况。

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;

更多案例请见commit 173e6c8 , 使用 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

这说明了 git 中的索引有 3 个阶段(参见“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

这里,“都修改”是“在‘我们的’和‘他们的’中修改”。

关于git - 为什么git在冲突后输出git状态时说 "both modified"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25349227/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com