在Git中,我该如何将当前提交散列写入同一提交中的文件 [英] In Git, how can I write the current commit hash to a file in the same commit

查看:88
本文介绍了在Git中,我该如何将当前提交散列写入同一提交中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Git钩子做一些奇特的东西,但我真的不知道该怎么做(或者如果可能的话)。

I'm trying to do a fancy stuff here with Git hooks, but I don't really know how to do it (or if it's possible).

我需要做的是:在每一次提交中,我想要使用它的散列,然后用这个散列提交一个文件。

What I need to do is: in every commit I want to take its hash and then update a file in the commit with this hash.

有什么想法?

推荐答案

我会建议您做一些类似于您的想法:将SHA1放入未跟踪的文件中,生成作为构建/安装/部署过程的一部分。这显然很容易( git rev-parse HEAD> filename 或者 git describe [--tags]> filename

I would recommend doing something similar to what you have in mind: placing the SHA1 in an untracked file, generated as part of the build/installation/deployment process. It's obviously easy to do (git rev-parse HEAD > filename or perhaps git describe [--tags] > filename), and it avoids doing anything crazy like ending up with a file that's different from what git's tracking.

然后,您的代码可以在需要版本时引用此文件编号或构建过程可以将信息结合到最终产品中。后者实际上是git本身如何获取其版本号 - 构建过程从版本库中获取版本号,然后将其构建到可执行文件中。

Your code can then reference this file when it needs the version number, or a build process could incorporate the information into the final product. The latter is actually how git itself gets its version numbers - the build process grabs the version number out of the repo, then builds it into the executable.

这篇关于在Git中,我该如何将当前提交散列写入同一提交中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆