"git diff --base" 到底是做什么的?

What exactly does "git diff --base" do?

我的笔记说 git diff --base 的功能是 "View the conflicts against the base file (the point where the two branches started diverting the considered file)" 但我无法在没有任何示例的情况下将其形象化。这与普通的 git diff 命令有何不同?

使用 git diff --base 仅对处于冲突状态的文件有意义,例如,在合并、cherry-pick 或 rebase 期间。

当文件foo发生冲突时,索引中记录了三个版本:"base"版本、"their"版本和"our"版本。正如您在笔记中所写,"base" 版本确实是两个分支开始分歧的文件版本。

因此,当您输入

git diff --base foo

您会看到工作树中 foo 的当前版本与基础版本的区别。

同样,您可以使用

git diff --theirs foo
git diff --ours foo

查看与冲突中涉及的其他两个版本的区别。