本文翻译自:How to output git log with the first line only?

I am trying to customize the format for git log . 我正在尝试自定义git log的格式。 I want all commits to be shown in one line. 我希望所有提交都显示在一行中。 Each line should only show the first line of the commit message. 每行应仅显示提交消息的第一行。
I found out that git log --pretty=short should do the trick but on my computer it shows the full log as git log does (besides the time stamp). 发现 git log --pretty=short应该可以解决这个问题,但是在我的计算机上它会显示完整的日志,就像git log一样(除了时间戳)。

Further, I tried to use the placeholders as defined in the man page . 此外,我尝试使用手册页中定义占位符 Though, I could not find a command to shorten the log message. 虽然,我找不到缩短日志消息的命令。 I tried this line git log --pretty=format:'%h : %s' which shows the shorted hash %h and the full message %s in one line. 我试过这行git log --pretty=format:'%h : %s' ,它显示了一行中的短git log --pretty=format:'%h : %s' %h和完整的消息%s

I am using git version 1.7.3.1.msysgit.0 on Vista. 我在Vista上使用git version 1.7.3.1.msysgit.0


Maybe it has something to do with the way I write my commit messages. 也许它与我编写提交消息的方式有关。 Here is an example: 这是一个例子:

Added some functionality.
+ Added print function in Foo class.
+ Added conversion from foo to baz.

So, with the example given I only want to be output Added some functionality. 因此,通过给出的示例我只想输出Added some functionality. prepended by the shortend hash. 以shortend哈希为前缀。


#1楼

参考:https://stackoom.com/question/iNfz/如何只用第一行输出git-log


#2楼

You can define a global alias so you can invoke a short log in a more comfortable way: 您可以定义全局别名,以便以更舒适的方式调用短日志:

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

Then you can call it using git slog (it even works with autocompletion if you have it enabled). 然后你可以使用git slog调用它(如果你启用它,它甚至可以用于自动完成)。


#3楼

Better and easier git log by making an alias . 通过创建别名来 更好 更容易地进行 git日志。 Paste the code below to terminal just once for one session. 将下面的代码粘贴到终端只需一次会话。 Paste the code to zshrc or bash profile to make it persistant. 将代码粘贴到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"

Output 产量

git lg

Output changed lines 输出更改了行

git lg -p

Alternatively (recommended) 或者 (推荐)
Paste this code to global .gitconfig file 将此代码粘贴到全局.gitconfig文件

[alias]
  lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

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


#4楼

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

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

#5楼

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


#6楼

if you want to always use git log in such way you could add git alias by 如果你想总是以这种方式使用git log ,你可以添加git别名

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

after that git log will print what normally would be printed by git log --oneline 之后, git log将打印通常由git log --oneline打印的git log --oneline

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐