简体   繁体   English

如何让'git diff'只显示提交消息

[英]How to get 'git diff' to only show commit messages

How do I use git diff to only show commit messages?如何使用git diff仅显示提交消息?

I just want the message of the commit, not the name of the files.我只想要提交的消息,而不是文件的名称。 I am trying to get a change log in Git.我正在尝试在 Git 中获取更改日志。

You could try git log , thus,你可以试试git log ,因此,

git log commitA...commitB

The triple dot notation '...' gives you just the commit messages for all the commits that are reachable from commitA or commitB, but not from both - ie, the diff between commitA and commitB.三点符号 '...' 只为您提供可从 commitA 或 commitB 访问的所有提交的提交消息,但不能同时从两者访问 - 即 commitA 和 commitB 之间的差异。

You can easily strip down to just the commit message with something like:您可以使用以下内容轻松地将提交消息精简为:

git log --pretty=%B commitA...commitB

Some examples一些例子

# Show a log of all commits in either the development branch or master branch since they diverged.
git log --pretty=%B development...master
# Ahow a log of all commits made to either commit b8c9577  or commit 92b15da, but not to both.
git log --pretty=%B b8c9577...92b15da
# Show a log for all commits unique to either the local branch master or local version of the origin's master branch.
git co master
git log --pretty=%B master...origin/master
# Show a log for all commits unique to either the local HEAD or local version of the origin's master branch.
git co master
# Hack, hack
git log --pretty=%B HEAD...origin/master

Use:用:

git log --oneline -n 10

It will print out the last n (10) commits on single lines.它将在单行上打印出最后n (10) 次提交。 Just the commit messages.只是提交消息。

You can also combine it with other log parameters, like:您还可以将其与其他日志参数结合使用,例如:

git log --oneline --graph --decorate -n 10

In addition to Simon Clewer's answer:除了西蒙克莱尔的回答:

git log master..dev --no-merges --pretty='format:%cs %s'

It prints only subjects of commits between master and development (without merge commits).它只打印 master 和 development 之间的提交主题(没有合并提交)。 Something like this:像这样的东西:

2020-12-31 Hot fix
2020-12-30 Change some stuff
2020-12-29 Add the feature

Changes between local and remote branches:本地和远程分支之间的变化:

git log HEAD..origin --no-merges --pretty='format:%cs %s'

See also What are some good ways to manage a changelog using Git?另请参阅使用 Git 管理变更日志的一些好方法是什么? . .

git log --pretty=%B

will show you the last commit messages.将显示最后的提交消息。

In case you want to limit the number of commit messages shown by a number, N , you can do this by providing an additionally -N , eg,如果您想限制由数字N显示的提交消息的数量,您可以通过提供额外的-N ,例如,

git log -3 --pretty=%B

for the last three commit messages.对于最后三个提交消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM