提示:解决冲突后,请标记已更正的路径。

57

有时候在撤销或挑选提交时,git会给我一个冲突的提示信息

hint: after resolving the conflicts, mark the corrected paths

这是什么意思?

3个回答

57

这意味着您需要明确告诉Git您已经解决了每个文件或文件夹(即路径)中的冲突。

1. 查看仍有未解决冲突的文件列表

git status

2. 标记每个已解决的文件

一旦你已经解决了一个文件中的冲突,添加标记以表示冲突已经解决:

git add file-which-had-conflicts

如果您想删除文件而不是解决冲突,请使用 git rm 。但这是罕见情况。

git rm file-which-had-conflicts

3. 进行变基/合并/其他操作

git rebase --continue
git merge --continue
git cherry-pick --continue

2
“git commit” 不一定是最终步骤,例如在 “rebase” 过程中。 - Sascha Wolf
当在git status中除了changelog.md文件外没有其他文件显示,但我确定提交中除了changelog之外还有其他更改时,问题出在哪里? - Gobliins
@NickVolynkin 今天我在处理另一个问题,周一我回来后会告诉你 git diff 会返回什么。 - Gobliins
你是说通过使用 git add . 我就可以标记一个冲突为已解决状态了吗? - Rich
1
@Rich git add file-which-had-conflicts -> @Rich git添加有冲突的文件 - Nick Volynkin
显示剩余3条评论

5

1

这可能会让人感到困惑,但是在Git 2.34(2021年第四季度)中,“git cherry-pick(man)给出的建议信息更清晰了:

当它要求用户解决提交的冲突回放时,现在(Git 2.34,2021年第四季度)会说:

  • 对于git cherry-pick
After resolving the conflicts, mark them with
`git add`/`rm <pathspec>`, then run
`git cherry-pick --continue`

You can instead skip this commit with `git cherry-pick --skip`.

To abort and get back to the state before `git cherry-pick`
run `git cherry-pick --abort`.
  • 对于 git revert
After resolving the conflicts, mark them with
`git add`/`rm <pathspec>`, then run
`git revert --continue`

You can instead skip this commit with `git revert --skip`.

To abort and get back to the state before `git revert`
run `git revert --abort`.

请查看提交 f172556(2021年8月22日)由ZheNing Hu(adlternative完成。
(于2021年9月10日由Junio C Hamano -- gitster --提交 173368d中合并)

cherry-pick: 使用更好的建议信息

指导者:Christian Couder
指导者:Hariom Verma
协助者:Phillip Wood
协助者:Junio C Hamano
签署者:ZheNing Hu

"git cherry-pick"(man), upon seeing a conflict, says:

hint: after resolving the conflicts, mark the corrected paths 
hint: with `git add <paths>` or `git rm <paths>` 
hint: and commit the result with `git commit`.

As if running "git commit" to conclude the resolution of this single step were the end of the story.

This stems from the fact that the command originally was to pick a single commit and not a range of commits, and the message was written back then and has not been adjusted.

When picking a range of commits, and the command stops with a conflict in the middle of the range, however, after resolving the conflict and (optionally) recording the result with "git commit", the user has to run "git cherry-pick --continue" to have the rest of the range dealt with, "--skip" to drop the current commit, or "--abort" to discard the series.

Suggest use of "git cherry-pick --continue/--skip/--abort so that the message also covers the case where a range of commits are being picked.

Similarly, this optimization can be applied to git revert(man), suggest use of "git revert --continue/--skip/--abort so that the message also covers the case where a range of commits are being reverted.

It is worth mentioning that now we use advice() to print the content of GIT_CHERRY_PICK_HELP in print_advice(), each line of output will start with "hint: ".


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接