我正在尝试使用 git log -L <start>,<end>:<filename>
但我希望输出非常有限(实际上只是散列)。虽然 --pretty 以我想要的格式打印提交信息,但我没有找到不显示差异的方法...
例如在 linux-next 上,我尝试的是:
git log --pretty=format:"%H" -s -L 70,70:./arch/x86/include/asm/irqflags.h
其中(根据联机帮助页)-s 应该抑制 diff 的输出,但是输出是:
$ git log --pretty=format:"%H" -s -L 70,70:./arch/x86/include/asm/irqflags.h
6abcd98ffafbff81f0bfd7ee1d129e634af13245
diff --git a/include/asm-x86/irqflags.h b/include/asm-x86/irqflags.h
--- a/include/asm-x86/irqflags.h
+++ b/include/asm-x86/irqflags.h
@@ -1,2 +64,1 @@
-#ifdef CONFIG_X86_32
-# include "irqflags_32.h"
+{
96a388de5dc53a8b234b3fd41f3ae2cedc9ffd42
diff --git a/include/asm-x86/irqflags.h b/include/asm-x86/irqflags.h
--- /dev/null
+++ b/include/asm-x86/irqflags.h
@@ -0,0 +1,2 @@
+#ifdef CONFIG_X86_32
+# include "irqflags_32.h"
我使用的是 git 版本 2.10.2
最佳答案
Git 2.22(2019 年第 2 季度)会更加清晰。
“git log -L<from>,<to>:<path>
”和“-s
”没有打补丁
应有的输出。
这已得到纠正。
参见 commit 05314ef (2019 年 3 月 11 日),以及 commit 9f607cd (2019 年 3 月 7 日)作者:Jeff King ( peff
) .
(由 Junio C Hamano -- gitster
-- 在 commit 31df2c1 中 merge ,2019 年 4 月 9 日)
line-log
: detect unsupported formats
If you use "
log -L
" with an output format like "--raw
" or "--stat
", we'll silently ignore the format and just output the normal patch.
Let's detect and complain about this, which at least tells the user what's going on.
现在它会清楚地显示:
-L does not yet support diff formats besides -p and -s
在 Git 2.25(2020 年第一季度)中,文档增加了更多内容。
参见 commit 2be4586 , commit 2be4586 (2019 年 12 月 26 日)Philippe Blain ( phil-blain
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit c4117fc,2020 年 1 月 6 日)
doc:
log
,gitk
: document accepted line-log diff formats
Currently the line-log functionality (
git log -L
) only supports displaying patch output (-p | --patch
, its default behavior) and suppressing it (-s | --no-patch
).
A check was added in the code to that effect in 05314ef (line-log
: detect unsupported formats, 2019-03-10) but the documentation was not updated.Explicitly mention:
- that
-L
implies-p
, that patch output can be suppressed using-s
,- and that all other diff formats are not allowed.
和:
The line number, regex or offset parameters and in
git log -L <start>,<end>:<file>
, or the function name regex ingit log -L :<funcname>:<file>
must exist in the starting revision, or else the command exits with a fatal error.
所以,除了You can specify this option more than once
,你有:
Implies
--patch
.
Patch output can be suppressed using--no-patch
, but other diff formats (namely--raw
,--numstat
,--shortstat
,--dirstat
,--summary
,--name-only
,--name-status
,--check
) are not currently implemented.
在 Git 2.30(2021 年第一季度)中,“ git log
( man )” 被记录为不采用路径规范,但这不是由命令行选项解析器强制执行的,它已被更正。
参见 commit 39664cb (2020 年 11 月 4 日)Junio C Hamano ( gitster
) .
(由 Junio C Hamano -- gitster
-- merge 于 commit f8a1cee,2020 年 11 月 18 日)
log
: diagnose-L
used with pathspec as an errorHeled-by: Jeff King
The
-L
option is documented to accept no pathspec, but the command line option parser has allowed the combination without checking so far.
Ensure that there is no pathspec when the-L
option is in effect to fix this.Incidentally, this change fixes another bug in the command line option parser, which has allowed the
-L
option used together with the--follow
option.
Because the latter requires exactly one path given, but the former takes no pathspec, they become mutually incompatible automatically.
Because the-L
option follows renames on its own, there is no reason to give--follow
at the same time.The new tests say they may fail with "
-L
and--follow
being incompatible" instead of "-L
and pathspec being incompatible". Currently, the expected failure can come only from the latter, but this is to future-proof them, in case we decide to add code to explicitly die on-L
and--follow
used together.
关于git log -L 没有差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41427590/