Git - 获取当前工作副本版本

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

Git - Get Current Working Copy Version

gitgithub

提问by vcsjones

I am editing a project with git on multiple computers. How do I check the current version I am running on a computer?

我正在多台计算机上使用 git 编辑一个项目。如何检查我在计算机上运行的当前版本?

For example, each time I commit, I use a version number and include it in the commit message. Is there a way for me to retrieve the current commit message for the working copy I am using?

例如,每次提交时,我都会使用一个版本号并将其包含在提交消息中。有没有办法让我检索我正在使用的工作副本的当前提交消息?

回答by xpapad

You can use git rev-parse HEAD

您可以使用git rev-parse HEAD

If you use maven to build your projects, consider using the maven SCM plugin, see:

如果您使用 maven 构建您的项目,请考虑使用 maven SCM 插件,请参阅:

http://maven.apache.org/scm/git.html

http://maven.apache.org/scm/git.html

回答by vcsjones

Git does not have a concept of a "Revision Number". It has a commit hash. You won't know your commit hash until you've actually commited, so you cannot get the "current hash".

Git 没有“修订号”的概念。它有一个提交哈希。在您实际提交之前,您不会知道您的提交哈希,因此您无法获得“当前哈希”。

If you want the commit hash of the previous commit, use git log -1. If you need the output to be justthe hash, then xpapad's answer is what you are looking for.

如果您想要上一次提交的提交哈希,请使用git log -1. 如果您需要输出只是散列,那么 xpapad 的答案就是您要找的。

If you mean the actual version of Git (your question was a little ambiguous to me), then use git version.

如果你的意思是 Git 的实际版本(你的问题对我来说有点含糊不清),那么使用git version.

回答by William Pursell

It sounds like you want git-describe. That is the closes thing git has to a monotonic version number.

听起来您想要 git-describe。这就是 git 对单调版本号的关闭。