git log -L without diff

2019-02-20 05:12发布

I'm trying to use git log -L <start>,<end>:<filename> but I would like to have very limited output (actually just hashes). While --pretty prints the commit info in the format I want, I did not find a way to not display the diff...

e.g. on linux-next what I tried is:

git log --pretty=format:"%H" -s -L 70,70:./arch/x86/include/asm/irqflags.h

where (according to the manpage) the -s is supposed to Supress the ouput of the diff, however the output is:

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

I am using git version 2.10.2

标签: git git-log
2条回答
一夜七次
2楼-- · 2019-02-20 05:48

one grep solution is to pipe the output to grep to only print lines matching a commit:

git log -L 10,11:example.txt | grep 'commit \w' -A 4

grep matches the first line of each log entry and the prints the next 4 lines with the -A flag

It's a bit verbose though. Would love to hear if anyone has a better solution!

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-02-20 06:09

The -L option is not currently (and apparently never was) compatible with -s / --no-patch, because of this code called from line_log_print, called from the top of log_tree_commit when -L is in effect. Said code simply outputs the entire chosen line-range from any matched commit. (You could patch the hack to obey the diff output options, perhaps.)

(The other obvious workaround would be to use git rev-list instead of git log, except that -L is, as that first link notes, not properly integrated in the first place, so that git rev-list does not handle it.)

查看更多
登录 后发表回答