git 如何仅输出第一行的git log?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4479225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to output git log with the first line only?
提问by JJD
I am trying to customize the format for 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 outthat 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
. 我希望所有提交都显示在一行中。每行应该只显示提交消息的第一行。
我发现这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'
,它在一行中显示了短散列%h
和完整消息%s
。
I am using git version 1.7.3.1.msysgit.0
on Vista.
我git version 1.7.3.1.msysgit.0
在 Vista 上使用。
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.
prepended by the shortend hash.
因此,在给出的示例中,我只想输出Added some functionality.
缩短的哈希值。
回答by Gauthier
Have you tried this?
你试过这个吗?
git log --pretty=oneline --abbrev-commit
The problem is probably that you are missing an empty line after the first line. The command above usually works for me, but I just tested on a commit without empty second line. I got the same result as you: the whole message on one line.
问题可能是您在第一行之后缺少一个空行。上面的命令通常对我有用,但我只是在没有空的第二行的情况下测试了提交。我得到了和你一样的结果:一行上的全部信息。
Empty second line is a standard in git commit messages. The behaviour you see was probably implemented on purpose.
空的第二行是 git commit 消息中的标准。您看到的行为可能是故意实施的。
The first line of a commit message is meant to be a short description. If you cannot make it in a single line you can use several, but git considers everything before the first empty line to be the "short description". oneline
prints the whole short description, so all your 3 rows.
提交消息的第一行是一个简短的描述。如果您不能在一行中创建它,您可以使用多个,但 git 将第一个空行之前的所有内容视为“简短描述”。oneline
打印整个简短的描述,所以你所有的 3 行。
回答by 9000
Does git log --oneline
do what you want?
是否git log --oneline
你想要做什么?
回答by atilkan
Betterand easiergit log by making an alias. Paste the code below to terminal just once for one session. Paste the code to zshrc or bash profile to make it persistant.
更好的和更容易通过做一个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"
Output
输出
git lg
Outputchanged 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
Advanced Reading.
http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/
进一步阅读。
https://coderwall.com/p/euwpig/a-better-git-log
高级阅读。
http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/
回答by technophyle
This will print out just the message (subject line only) without hash:
这将只打印不带 hash的消息(仅主题行):
git log --pretty=format:%s
回答by That Brazilian Guy
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"
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
它来调用它(如果你启用了它,它甚至可以与自动完成一起使用)。
回答by otiai10
Without commit messages, only the hash:
没有提交消息,只有散列:
git log --pretty=oneline | awk '{print }'
回答by noisy
if you want to always use git log
in such way you could add git alias by
如果您想始终git log
以这种方式使用,您可以通过以下方式添加 git alias
git config --global alias.log log --oneline
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