Git log和git show有不同的漂亮格式吗?

6

我在.gitconfig中有以下内容:

[format]
    pretty = %C(yellow)%h%Cred%d%Creset - %C(cyan)%an %Creset: %s %Cgreen(%cr)

这将使git log的输出看起来像这样(加上一些漂亮的颜色):
6b1d043 (origin/master) - Ismail Badawi : Don't redirect to index after saving query. (28 hours ago)
df98a3e - Ismail Badawi : Store example queries in database & cache results (30 hours ago)
6de44ab - Ismail Badawi : Add sanity check tests for different pages. (31 hours ago)
7b6b46b - Ismail Badawi : Save query results for saved queries. (31 hours ago)

我认为这种格式易于浏览。但我不喜欢它也影响了git show;特别是,我希望在git show的输出中能够看到完整的提交信息,而不仅仅是标题行;还有实际日期,而不是相对日期,作者电子邮件等。
是否有办法为git loggit show使用不同的默认格式?

为什么不使用别名呢? - Pranav 웃
1个回答

3

git logshow都使用相同的配置。

--format=<format>
    Pretty-print the contents
    ...
    Note: you can specify the default pretty format in the repository configuration (see git-config(1)).

https://www.kernel.org/pub/software/scm/git/docs/git-show.html

然而,为什么不定义一个别名来代替它们中的一个呢?例如,您可以使用 git alias.vshow 'show --pretty=<your other format string>' 来定义一个别名。

这样做可以帮助您更方便地使用其他格式字符串。


2
我不喜欢同时拥有showvshow的想法,并理解show从来不是我想要的,而vshow永远是我想要的。这感觉不对 - 直觉上,我正在改变show的行为,而不是引入一个新命令。(相比之下,我有各种别名可以向diff添加标志,但在某些情况下我仍然使用裸体diff)。如果git允许您定义遮盖命令的别名,那么我会这样做。 - Ismail Badawi
你说得对,覆盖命令是不可能的,这就是 git 中处理循环的编码方式,内部命令会在别名之前查找。但同样地,这就是漂亮格式定义的方式,它在“log”和“show”之间共享。 - mockinterface
另一个类似的解决方案是使用Bash(或其他shell)别名代替Git别名。但我同意@Ismail Badawi的观点,这感觉不对,最好在git配置中为“log”和“show”指定不同的格式。 - Alexei Khlebnikov

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