是否有可能在事后找出合并提交中哪些文件发生冲突?或者强制 git 在提交消息中列出文件的方法?

Is it possible to find out which files conflicted in a merge commit after the fact? Or a way to force git to list the files in the commit message?

我想知道发生合并冲突时哪些文件git无法自动合并。我找到了这个答案: How to list conflicted files (files with changes in both parents) in a git merge commit?

但是刚刚测试了git show --name-status,但在我的情况下它不起作用,我知道有冲突的文件没有出现在列表中...

或者,我想知道在以某种方式进行合并提交时是否可以强制将这些文件包含在 git 提交消息中?或者至少更改默认的 git 行为,以便默认情况下不会注释掉文件? (显然是为了使用存储库为我团队中的每个人进行此更改)

是的,但它涉及 Git 钩子,这很麻烦(见下文)。在极少数情况下,您需要此类信息,您可以重新创建冲突。

假设您正在查看此存储库。

A - B - F - G -- M - N - O [master]
     \         /
      C - D - E

而您想了解 M 处的冲突。签出 G 并合并 E。

git checkout G
git merge E

任何冲突都会被复制。


I would like to know which files git was not able to automatically merge when a merge conflict happened.

Git 不会记录哪些文件在合并提交中发生冲突。此信息是短暂的。

Alternatively, I'm wondering if it's possible to force these files to be included in the git commit message when doing a merge commit somehow? Or at least to change the default git behaviour so that the files aren't commented out by default?

是的。然而...

(to make this change for everyone on my team using a repository obviously)

不会自动。

您可以使用 prepare-commit-msg hook to edit the commit message. The first argument is the original file and the second is the source (you're looking for merge). You can write a hook that either uncomments the existing conflict lines, or write your own file with the list of conflicted files.

但是,Git 挂钩未随存储库一起分发。您团队中的每个人都必须安装它们并使它们保持最新。

无法在服务器端更改提交消息(即在推送之后),因为提交消息是提交的一部分。更改消息会更改提交 ID。