git log --exit-code是什么意思?

12
git-log man页中描述了--check选项与--exit-code选项不兼容。我想知道这个--exit-code是什么意思,但我无法在任何地方找到它。我尝试了man git logman git、Google和直接搜索SO...都没有结果! --exit-code对于git log来说是什么意思?

有一些有限的方式可以让--exit-code与log(而不是diff)配合使用,因为log可以像diff一样支持标志,如--ignore-whitesape、--ignore-space-at-eol等。因此,即使没有-p(打印补丁)git log -w -n 1 HEAD --exit-code也会根据补丁中是否有非空格更改而给出不同的结果。 - Joshua Goldberg
2个回答

10

简述

我想知道 --exit-code 是什么意思[...]

--exit-code 是一个 diff-*1 选项,如果有更改则使Git命令以1退出,否则为0

[...] 但我无法在任何地方找到它。

您可以在git-diff手册页中阅读有关它的信息(它只在git-log手册页中提及)。

更多细节

git-diff手册页中描述了--check--exit-code两个选项(更具体地说,在Documentation/diff-options.txt中):

   --check
 Warn if changes introduce whitespace errors. What are considered
 whitespace errors is controlled by core.whitespace configuration.
 By default, trailing whitespaces (including lines that solely
 consist of whitespaces) and a space character that is immediately
 followed by a tab character inside the initial indent of the line
 are considered whitespace errors. Exits with non-zero status if
 problems are found. Not compatible with --exit-code.

并且

   --exit-code
 Make the program exit with codes similar to diff(1). That is, it
 exits with 1 if there were differences and 0 means no differences.
一些 diff-* 选项与 git-log 兼容,而不是全部兼容。如下来自 Git项目存储库提交消息 所示,--check 选项是兼容的,而 --exit-code 选项则不兼容:

docs: 不要在 git-log(1) 中提及 --quiet--exit-code

这些是 diff 选项,但在 log 上下文中实际上没有意义。

(1) diff-* 代表基于瓷器 git-diff 的管道命令。


2
在“日志”上下文中,“--exit-code”确实有意义,特别是在使用“--grep”时。 - Jonathan Hall

2
git-diff文档中提到(显然不打算与git-log一起使用):

“使程序以类似于diff(1)的代码退出。也就是说,如果有差异,则退出1,而0表示没有差异。”


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