如何在 Git 中检索当前提交的哈希值? [英] How to retrieve the hash for the current commit in Git?
问题描述
我想(暂时)保留将 Git 变更集链接到存储在 TFS 中的工作项的能力.
I would like to retain (for now) the ability to link Git changesets to workitems stored in TFS.
我已经编写了一个工具(使用来自 Git 的钩子),我可以在其中将工作项标识符注入 Git 变更集的消息中.
I already wrote a tool (using a hook from Git) in which I can inject workitem identifiers into the message of a Git changeset.
我还想将 Git 提交的哈希值存储在自定义 TFS 工作项字段中.通过这种方式,我可以检查 TFS 中的工作项并查看哪些 Git 变更集与该工作项相关联.
I would also like to store the hash of the Git commit in a custom TFS workitem field. This way I can examine a workitem in TFS and see what Git changesets are associated with the workitem.
如何轻松地从 Git 的当前提交中检索哈希?
How can I easily retrieve the hash from the current commit from Git?
推荐答案
要将任意扩展对象引用转换为 SHA-1,只需使用 git-rev-parse,例如
To turn arbitrary extended object reference into SHA-1, use simply git-rev-parse, for example
git rev-parse HEAD
或
git rev-parse --verify HEAD
您也可以像这样检索简短版本
You can also retrieve the short version like this
git rev-parse --short HEAD
旁注:如果你想把引用(分支和标签) 进入 SHA-1,有 git show-ref
和 git for-each-ref
.
Sidenote: If you want to turn references (branches and tags) into SHA-1, there is git show-ref
and git for-each-ref
.
这篇关于如何在 Git 中检索当前提交的哈希值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!