获取简短的 Git 版本哈希
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5694389/
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
Get the short Git version hash
提问by Attila O.
Is there a cleaner way to get the short version hash of HEAD
from Git?
有没有更简洁的方法来HEAD
从 Git获取短版本哈希?
I want to see the same output as I get from:
我想看到与我得到的输出相同的输出:
git log -n 1 | head -n 1 | sed -e 's/^commit //' | head -c 8
I originally used the above command to generate a version string, but this is even better:
我最初使用上面的命令来生成版本字符串,但这更好:
git describe --tags
It will output strings like 0.1.12
(tagged commit) or 0.1.11-5-g0c85fbc
(five commits after the tag).
它将输出像0.1.12
(tagged commit) 或0.1.11-5-g0c85fbc
(在标签之后的五个提交) 之类的字符串。
回答by Mark Longair
Try this:
尝试这个:
git rev-parse --short HEAD
The command git rev-parse
can do a remarkable number of different things, so you'd need to go through the documentationvery carefully to spot that though.
该命令git rev-parse
可以做很多不同的事情,所以你需要非常仔细地阅读文档才能发现它。
回答by Karl Bielefeldt
You can do just about any format you want with --pretty=format:
你可以做任何你想要的格式 --pretty=format:
git log -1 --pretty=format:%h
回答by Sanjeev
git log -1 --abbrev-commit
will also do it.
也会这样做。
git log --abbrev-commit
will list the log entries with abbreviated SHA-1 checksum.
将列出带有缩写 SHA-1 校验和的日志条目。
回答by The Gilbert Arenas Dagger
A simple way to see the Git commit short version and the Git commit message is:
查看 Git 提交简短版本和 Git 提交消息的简单方法是:
git log --oneline
Note that this is shorthand for
请注意,这是简写
git log --pretty=oneline --abbrev-commit
回答by Steven Shaw
A really simple way is to:
一个非常简单的方法是:
git describe --always
回答by Fabrice
Branch with short hash and last comment:
带有短哈希和最后评论的分支:
git branch -v
develop 717c2f9 [ahead 42] blabla
* master 2722bbe [ahead 1] bla
回答by Down the Stream
I have Git version 2.7.4 with the following settings:
我有具有以下设置的 Git 版本 2.7.4:
git config --global log.abbrevcommit yes
git config --global core.abbrev 8
Now when I do:
现在当我这样做时:
git log --pretty=oneline
I get an abbreviated commit id of eight digits:
我得到一个八位数字的缩写提交 ID:
ed054a38 add project based .gitignore
30a3fa4c add ez version
0a6e9015 add logic for shifting days
af4ab954 add n days ago
...
回答by velocity
what about this :
那这个呢 :
git log --pretty="%h %cD %cn %s"
it shows someting like :
它显示类似:
674cd0d Wed, 20 Nov 2019 12:15:38 +0000 Bob commit message
674cd0d 2019 年 11 月 20 日星期三 12:15:38 +0000 Bob 提交消息
see the pretty format documentation enter link description here
请参阅漂亮的格式文档在此处输入链接描述