git 如何阅读上次提交评论?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7293008/
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 read last commit comment?
提问by whamsicore
Often during a commit ($ git -commit -m ""
), I wish to read my last comment to remember what progress I have made. Is there an easy way to directly access the last commit message through command-line? (I'm using Windows.)
通常在提交 ( $ git -commit -m ""
)期间,我希望阅读我的最后一条评论以记住我取得了哪些进展。有没有一种简单的方法可以通过命令行直接访问最后一个提交消息?(我正在使用 Windows。)
回答by CB Bailey
git show
is the fastest to type, but shows you the diff as well.
是最快的输入方式,但也会向您显示差异。
git log -1
is fast and simple.
快速而简单。
git log -1 --pretty=%B
if you need just the commit message and nothing else.
如果您只需要提交消息而不需要其他任何内容。
回答by Abizern
Generally:
一般来说:
git log -n
will show you the last n
commit messages
将向您显示最后的n
提交消息
More elegantly - if you want a quick overview of your commits
更优雅 - 如果您想快速了解您的提交
git log --oneline -n
This will Show just the first line of the last n
commit messages.
这将只显示最后n
提交消息的第一行。
You can save this as a git alias or a shell alias with a shorter command. I've got it in my shell as glog
, for example, and I can see my last 10 commit messages with glog -10
.
您可以使用较短的命令将其保存为 git 别名或 shell 别名。glog
例如,我在我的 shell 中将它作为glog -10
.
回答by Gregory Pakosz
git log -1
will display the latest commit message or git log -1 --oneline
if you only want the sha1 and associated commit message to be displayed.
git log -1
将显示最新的提交消息,或者git log -1 --oneline
如果您只想显示 sha1 和相关的提交消息。
回答by nos
You can use
您可以使用
git show -s --format=%s
Here --format
enables various printing options, see documentation here. Specifically, %s
means 'subject'. In addition, -s
stands for --no-patch
, which suppresses the diff content.
此处--format
启用各种打印选项,请参阅此处的文档。具体来说,%s
意思是“主题”。此外,-s
代表--no-patch
,它抑制差异内容。
I often use
我经常用
git show -s --format='%h %s'
where %h
denotes a short hash of the commit
其中%h
表示提交的简短哈希
Another way is
另一种方式是
git show-branch --no-name HEAD
It seems to run faster than the other way.
它似乎比其他方式运行得更快。
I actually wrote a small tool to see the status of all my repos. You can find it on github.
我实际上写了一个小工具来查看我所有 repos 的状态。你可以在github上找到它。
回答by CJ Dennis
git log -1 branch_name
will show you the last message from the specified branch (i.e. not necessarily the branch you're currently on).
git log -1 branch_name
将显示来自指定分支的最后一条消息(即不一定是您当前所在的分支)。
回答by sungiant
For something a little more readable, run this command once:
对于更具可读性的内容,请运行此命令一次:
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
so that when you then run:
这样当你运行时:
git lg
you get a nice readout. To show only the last line:
你会得到一个很好的读数。只显示最后一行:
git lg -1
Solution found here
解决方案在这里找到
回答by nehem
To start with git log -1 --pretty='%s'
开始 git log -1 --pretty='%s'
But the below one covers all the cases,
但是下面的一个涵盖了所有情况,
git log --pretty='format:%Creset%s' --no-merges -1
git log --pretty='format:%Creset%s' --no-merges -1
- No unwanted white spaces
- Discards merge commits
- No commit id, date, Displays only the messages.
- 没有不需要的空格
- 丢弃合并提交
- 无提交 ID、日期、仅显示消息。
Paste & see for yourself
粘贴并亲自查看
回答by LukePOLO
I did this
我做了这个
git reflog -1 | sed 's/^.*: //'
回答by Steve S.
I just found out a workaround with shell by retrieving the previous command.
我刚刚通过检索上一个命令找到了 shell 的解决方法。
Press Ctrl-Rto bring up reverse search command:
按Ctrl-R 调出反向搜索命令:
reverse-i-search
reverse-i-search
Then start typing git commit -m, this will add this as search command, and this brings the previous git commit with its message:
然后开始输入git commit -m,这会将其添加为搜索命令,这会带来之前的 git commit 及其消息:
reverse-i-search`git commit -m`: git commit -m "message"
Enter. That's it!
进入。就是这样!
(tested in Ubuntu shell)
(在 Ubuntu shell 中测试)