在 Git 中,我如何确定我当前的修订版本是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5724513/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:41:20  来源:igfitidea点击:

In Git, how do I figure out what my current revision is?

git

提问by TIMEX

I just want to know what my current version number is.

我只想知道我当前的版本号是多少。

回答by William Pursell

What do you mean by "version number"? It is quite common to tag a commit with a version number and then use

“版本号”是什么意思?用版本号标记提交然后使用是很常见的

$ git describe --tags

to identify the current HEAD w.r.t. any tags. If you mean you want to know the hash of the current HEAD, you probably want:

识别当前的 HEAD wrt 任何标签。如果您想知道当前 HEAD 的哈希值,您可能需要:

$ git rev-parse HEAD

or for the short revision hash:

或者对于简短的修订哈希:

$ git rev-parse --short HEAD

It is often sufficient to do:

这样做通常就足够了:

$ cat .git/refs/heads/${branch-master}

but this is not reliable as the ref may be packed.

但这并不可靠,因为 ref 可能已打包。

回答by manojlds

There are many ways git log -1is the easiest and most common, I think

有很多方法git log -1是最简单最常用的,我觉得

回答by htanata

This gives you just the revision.

这只是给你修订。

git rev-parse HEAD

回答by Ken McConnell

This gives you the first few digits of the hash and they are unique enough to use as say a version number.

这为您提供了哈希的前几位数字,它们足够独特,可以用作版本号。

git rev-parse --short HEAD

git rev-parse --short HEAD

回答by Alexey Bychko

below will work with any previously pushed revision, not only HEAD

下面将适用于任何先前推送的修订,而不仅仅是 HEAD

for abbreviated revision hash:

对于缩写修订哈希:

git log -1 --pretty=format:%h

for long revision hash:

对于长修订哈希:

git log -1 --pretty=format:%H