Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
423 views
in Technique[技术] by (71.8m points)

git - 如何在Git中检索当前提交的哈希值?(How to retrieve the hash for the current commit in Git?)

I would like to retain (for now) the ability to link Git changesets to workitems stored in TFS.

(我想保留(暂时)将Git变更集链接到存储在TFS中的工作项的功能。)

I already wrote a tool (using a hook from Git) in which I can inject workitemidentifiers into the message of a Git changeset.

(我已经编写了一个工具(使用Git的钩子),可以在其中将workitemidentifiers插入到Git变更集的消息中。)

However, I would also like to store the identifier of the Git commit (the hash) into a custom TFS workitem field.

(但是,我也想将Git提交的标识符(哈希)存储到自定义TFS工作项字段中。)

This way I can examine a workitem in TFS and see what Git changesets are associated with the workitem.

(这样,我可以检查TFS中的工作项,并查看与该工作项相关联的Git变更集。)

How can I easily retrieve the hash from the current commit from Git?

(如何轻松地从Git的当前提交中检索哈希?)

  ask by Sardaukar translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To turn arbitrary extended object reference into SHA-1, use simply git-rev-parse , for example

(要将任意扩展对象引用转换为SHA-1,例如,只需使用git-rev-parse)

git rev-parse HEAD

or

(要么)

git rev-parse --verify HEAD

Sidenote: If you want to turn references ( branches and tags ) into SHA-1, there is git show-ref and git for-each-ref .

(旁注:如果要将引用分支标签 )转换为SHA-1,则可以使用git show-refgit for-each-ref 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...