我正在尝试自定义git log
的格式。我希望所有提交都显示在一行中。每行应只显示提交消息的第一行。
Ifound outgit log --pretty=short
应该做的伎俩,但在我的计算机上,它显示完整的日志git log
(除了时间戳)。
此外,我尝试使用placeholders as defined in the man page。不过,我找不到缩短日志消息的命令。我尝试了这一行git log --pretty=format:'%h : %s'
,它在一行中显示了短路的哈希%h
和完整的消息%s
。
我在 Vista 上使用git version 1.7.3.1.msysgit.0
。
也许它与我写我的提交消息的方式有关。
Added some functionality.
+ Added print function in Foo class.
+ Added conversion from foo to baz.
因此,在给出的示例中,我只希望输出Added some functionality.
由短哈希开头。
你试过这个吗?
git log --oneline
它是git log --pretty=oneline --abbrev-commit
的别名,并显示“short sha”和“short description”,例如:
9bee8857 Write more code
831fdd6e Write some code Second line of message
问题是你在提交消息的第一行之后缺少一个空行。上面的命令通常对我有用,但我只是在没有空第二行的提交上进行了测试。我得到了和你一样的结果:整条消息在一行上。
空第二行是 git commit 消息中的一个标准。你看到的行为可能是故意实现的。
提交消息的第一行是一个简短的描述。如果你不能在一行中使用它,你可以使用几个,但是 git 认为第一个空行之前的所有内容都是“简短描述”。oneline
打印整个简短描述,所以你所有的 3 行。
git log --oneline
做你想做的事吗?
如果你需要没有哈希,只是第一行(主题行):
git log --pretty=format:%s
通过创建别名,使和更容易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
输出更改行
git lg -p
或者(推荐)
将此代码粘贴到全局.gitconfig 文件
[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
进一步阅读。
https://coderwall.com/p/euwpig/a-better-git-log
高级阅读。
http://durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(22条)