What does git log --exit-code mean?

2020-04-04 07:21发布

问题:

The git-log man page describes the --check option as incompatible with the --exit-code option. I'd like to know what this --exit-code means but I can't find it anywhere. I've tried man git log, man git, Google and direct search here on SO... to no avail!

What does --exit-code mean for git log?

回答1:

TL; DR

I'd like to know what this --exit-code means [...]

--exit-code is a diff-*1 option that makes the Git command exit with 1 if there are changes, and 0 otherwise.

[...] but I can't find it anywhere.

You can read about it in the git-diff man page (it's only mentioned in passing in the git-log man page).

More details

Both --check and --exit-code are described in the git-diff man page (more specifically, in 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.

and

   --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.

Some, though not all, diff-* options are compatible with git-log. The --check option is, whereas the --exit-code option is not, as hinted at by the following commit message from the Git-project repository:

docs: don't mention --quiet or --exit-code in git-log(1)

These are diff-options, but they don't actually make sense in the context of log.

(1) diff-* stands for the plumbing commands that porcelain git-diff is based on.



回答2:

It's mentioned in the git-diff docs (and is apparently not intended to be used with git-log):

"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."