git log缩写格式长度 [英] git log abbreviated format length
问题描述
我想从GIT日志中以缩写格式获取SHA编号.此命令将起作用:
I would like to get the SHA number from from GIT log in abbreviated format. This command will work:
git log -1 --format=%h
但是,默认的缩写格式为7个数字.有什么办法可以改变吗?
However, the default abbreviated format is 7 numbers in length. Is there any way to change that?
推荐答案
对于 git log
,-abbrev =< length>
参数控制输出的时间%h
和其他缩写哈希的值是:
For git log
, the --abbrev=<length>
parameter controls how long the output for %h
and other abbreviated hashes is:
$ git log -1 --format=%h --abbrev=4
d157
我还将注意到,使用 -1
(或-no-walk
)在这种情况下具有相同的效果,但是如果您指定几个提交标识符),如果您只需要提交 hash ,则使用 git log
是过分的: git rev-parse
将为您提供哈希值.出于显而易见的原因,用于将 git rev-parse
的提交ID限制为特定长度的控制旋钮拼写为-short
而不是-abbrev
;和 git rev-parse
要求您拼写 HEAD
,如果您的意思是 HEAD
,那么:
I will also note that when using -1
(or --no-walk
which has the same effect in this particular case, but is more useful if you specify several commit identifiers), if all you want is the commit hash, using git log
is overkill: git rev-parse
will get you the hash. For no obvious reason, the control knob for limiting git rev-parse
's commit IDs to a particular length is spelled --short
rather than --abbrev
; and git rev-parse
requires that you spell out HEAD
if you mean HEAD
, so:
$ git rev-parse --short=4 HEAD
d157
这篇关于git log缩写格式长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!