如何只用第一行输出git log?

时间:2010-12-18 17:39:26

标签: git version-control formatting logging commit-message

我正在尝试自定义git log的格式。我希望所有提交都显示在一行中。每行只应显示提交消息的第一行 git log --pretty=short git log git log --pretty=format:'%h : %s'应该可以解决问题但在我的计算机上显示%h的完整日志(除了时间戳)。

此外,我尝试使用found out。虽然,我找不到缩短日志消息的命令。我尝试了这一行%s,它在一行中显示了短信哈希git version 1.7.3.1.msysgit.0和完整邮件Added some functionality. + Added print function in Foo class. + Added conversion from foo to baz.

我在Vista上使用Added some functionality.


也许它与我编写提交消息的方式有关。这是一个例子:

{{1}}

因此,根据给出的示例,我只希望通过shortend哈希输出{{1}}。

9 个答案:

答案 0 :(得分:448)

你试过这个吗?

git log --pretty=oneline --abbrev-commit

问题可能是你在第一行后缺少一个空行。上面的命令通常适用于我,但我刚刚在没有空第二行的提交上进行了测试。我得到了与你相同的结果:整条信息在一行上。

空第二行是git commit消息中的标准。您看到的行为可能是故意实施的。

提交消息的第一行是简短描述。如果你不能在一行中创建它,你可以使用几个,但是git会将第一个空行之前的所有内容视为“简短描述”。 oneline打印整个简短描述,所有3行。

答案 1 :(得分:126)

git log --oneline能做你想做的吗?

答案 2 :(得分:29)

通过别名

更好更轻松 git日志。将下面的代码粘贴到终端只需一次会话。将代码粘贴到zshrc或bash配置文件以使其持久。

git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

输出

git lg

输出更改了行

git lg -p

进一步阅读。
https://coderwall.com/p/euwpig/a-better-git-log
高级阅读。
http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/

答案 3 :(得分:23)

您可以定义全局别名,以便以更舒适的方式调用短日志:

git config --global alias.slog "log --pretty=oneline --abbrev-commit"

然后你可以使用git slog来调用它(如果你启用它,它甚至可以用于自动完成)。

答案 4 :(得分:12)

这将仅打印出消息(仅主题行)而不散列:

git log --pretty=format:%s

答案 5 :(得分:8)

没有提交消息,只有哈希:

git log --pretty=oneline | awk '{print $1}'

答案 6 :(得分:1)

git log --format =“%H” -n 1

使用上述命令获取提交ID,希望对您有所帮助。

答案 7 :(得分:1)

如果只希望消息的第一行(主题):

for i in range(10):
    # display original images
    ax = plt.subplot(2, 20, i + 1)
    plt.imshow(example_images[i].reshape(28,28))
    plt.gray()
  
# display reconstructed images
    ax = plt.subplot(2, 20, 20 +i+ 1)
    plt.imshow(reconst_images[i].reshape(28,28))
    plt.gray()
   

plt.show()

,如果您希望该分支上的所有消息都返回主服务器:

<video>

最后但并非最不重要的一点,如果您想为快速降价发布说明添加小项目符号:

git log --pretty=format:"%s"

答案 8 :(得分:-6)

如果你想总是以这种方式使用git log,你可以通过

添加git别名

git config --global alias.log log --oneline

之后git log将打印git log --oneline

通常打印的内容