3

例如

> git cherry-pick <hash>
...
error: could not apply <hash>...
Resolved '<file>' using previous resolution.
> git mergetool
No files need merging
> git status
...
Unmerged paths:
  (use "git add <file>..." to mark resolution)

    both modified: <file>

“都修改了”和“没有文件需要合并”?说谎者!

4

2 回答 2

2

我猜这个问题不知何故git rerere得到了一个糟糕的合并。我认为这经常发生在 meld 没有完全意识到我按下 Ctrl-S 并将冲突标记记录到分辨率中时。为什么git仍然说“都已修改”并且不允许mergetool运行我不知道。无论如何,修复如下:

git rerere forget <file>
git checkout -m <file>
git mergetool

我希望git checkout -m暗示git rerere forget或 git status 更明确。本来可以节省一大堆时间。

于 2018-08-22T01:30:44.637 回答
0

你是正确git rerere的,线索是这一行:

Resolved '<file>' using previous resolution.

我之前没有意识到这一点(部分原因是我从未真正使用过git mergetool),但是:

为什么git仍然说“都已修改”并且不允许mergetool运行我不知道。

这是因为git mergetool用于git rerere remaining确定要合并的文件。

我使用重用的解决方案重新创建了您的合并冲突:

$ echo base version > file
$ git config rerere.enabled true
$ git add file && git commit -m 'create base'
[master 8e7a009] create base
 1 file changed, 1 insertion(+)
 create mode 100644 file
$ git checkout -b branch
Switched to a new branch 'branch'
$ echo 'branch conflict' >> file
$ git add file && git commit -m 'enter branch conflict'
[branch 6661ab7] enter branch conflict
 1 file changed, 1 insertion(+)
$ git checkout -b br2 master
Switched to a new branch 'br2'
$ echo 'different, hence conflict' >> file
$ git add file && git commit -m 'create br2 conflict'
[br2 9684589] create br2 conflict
 1 file changed, 1 insertion(+)
$ git merge branch
Auto-merging file
CONFLICT (content): Merge conflict in file
Recorded preimage for 'file'
Automatic merge failed; fix conflicts and then commit the result.

注意倒数第二行,它表明无论我现在做什么来解决冲突,Git 都会保存结果。

$ vim file

在这里,我解决了冲突(以一种更难显示的方式,因为全屏编辑)。

$ git add file && git commit -m resolution
Recorded resolution for 'file'.
[br2 8b42a26] resolution

提交记录的决议。我现在放弃了合并,然后再次运行它:

$ git reset --hard HEAD^
HEAD is now at 9684589 create br2 conflict
$ git merge branch
Auto-merging file
CONFLICT (content): Merge conflict in file
Resolved 'file' using previous resolution.
Automatic merge failed; fix conflicts and then commit the result.

请注意“使用以前的分辨率”行。

现在的状态是有未合并的路径:

$ git status
On branch br2
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)

        both modified:   file

no changes added to commit (use "git add" and/or "git commit -a")

git ls-files --stage确认存在三个版本的 file file

$ git ls-files --stage
100644 eb2222a53126bfe165c615e816f5ba268f1e628f 0       README
100644 4b9049d6a70d93a7af91b4f6b741b88ba1f1838a 1       file
100644 5974ab850c831f806f950321b08391ccea97efcf 2       file
100644 7a77704a9d365c790f5a24fe87515b8df0b7e91b 3       file

内容使用我保存的分辨率:

$ cat file
base version
resolved in br2

在启用 shell 跟踪的情况下运行git mergetool揭示了秘密:

+ USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [-O<orderfile>] [file to merge] ...'
+ SUBDIRECTORY_OK=Yes
[mass snippage]
+ git rerere remaining
+ set --
+ test 0 -eq 0
+ print_noop_and_exit
+ echo 'No files need merging'
No files need merging
+ exit 0

现在由我来做一些事情,比如你的把戏git rerere forget

$ git rerere forget file
Updated preimage for 'file'
Forgot resolution for file
$ git checkout -m file
$ cat file
base version
<<<<<<< ours
different, hence conflict
||||||| base
=======
branch conflict
>>>>>>> theirs

请注意,当我再次解析、添加和提交时,会记录新的解析:

$ git add file
$ git commit -m 're-resolved'
Recorded resolution for 'file'.
[br2 00c94b1] re-resolved

(当然,也可以git config rerere.enabled false。)

于 2018-08-22T05:45:50.717 回答