git 如何找出冲​​突中未合并的路径?

How does git figure out unmerged paths in conflicts?

git如何获取未合并路径列表?

我对git的理解是,在合并时,它会将更改合并到一个文件中,然后将其添加到索引中。如果发生合并冲突,则文件不会添加到索引中,而是留在带有冲突标记的工作树中。如果我 运行 git status 它会向我显示 unmerged paths 冲突文件。

git如何获取这些文件的列表?如果我 运行 git add 对于一个带有标记的冲突文件,它将不再显示为冲突,所以也许标记不是标识符?

If merge conflict occurs a file is not added in index and left in working tree with conflict markers.

在索引中:见git ls-files:

For an unmerged path, instead of recording a single mode/SHA-1 pair, the index records up to three such pairs; one from tree O in stage 1, A in stage 2, and B in stage 3.

git read-tree 详细说明 2 路合并:

Each "index" entry has two bits worth of "stage" state.
stage 0 is the normal one, and is the only one you’d see in any kind of normal use.

However, when you do git read-tree with three trees, the "stage" starts out at 1.

This means that you can do

git read-tree -m <tree1> <tree2> <tree3>

and you will end up with an index with all of the <tree1> entries in "stage1", all of the <tree2> entries in "stage2" and all of the <tree3> entries in "stage3".
When performing a merge of another branch into the current branch, we use the common ancestor tree as <tree1>, the current branch head as <tree2>, and the other branch head as <tree3>.

另请参阅“How do I force git to think a file is unmerged?”。