想要 git post receive hook 进行新的提交和推送

发布于 2024-11-06 07:35:09 字数 152 浏览 4 评论 0原文

我希望我的接收后挂钩负责更新存储库中的版本文件 本身,在一定条件下。所以,假设我的存储库中有一个文件 version.txt, 我希望 post receive 钩子能够更新 version.txt 中的版本字符串。

这意味着再次推动回购。这可能吗?

谢谢!

I would like my post-receive hook to be responsible for updating a version file in the repo
itself, under certain conditions. So, suppose I have a file version.txt in my repository,
I would like the post receive hook to update a version string inside version.txt.

That would mean another push to the repo. Is this possible?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

別甾虛僞 2024-11-13 07:35:09

您可以在服务器上拥有存储库的工作目录。在接收后,git pull 到工作目录,根据需要更新 version.txt 并提交和推送。这将再次触发 post-receive,所以要小心你如何进行条件更新,否则会进入一个循环。

#!/bin/sh
unset GIT_DIR
cd /path/to/repo.wd
git pull
echo "new content" > version.txt
git add version.txt
git commit -m "updating version.txt"
git push origin master

You can have a working directory of your repo on your server. In the post-receive, git pull on the working directory, update the version.txt as needed and commit and push. This will trigger the post-receive one more time, so be careful about how you are doing your conditional update, otherwise it will go into a cycle.

#!/bin/sh
unset GIT_DIR
cd /path/to/repo.wd
git pull
echo "new content" > version.txt
git add version.txt
git commit -m "updating version.txt"
git push origin master
旧梦荧光笔 2024-11-13 07:35:09

我不想尝试进行任何进一步的提交/推送,而是使用 按顺序过滤驱动程序,在签出/更新时能够为该 version.txt 文件生成正确的内容(即内部包含正确的版本字符串)

在此处输入图像描述

smudge 脚本(如果它能够识别 < 的内容) code>version.txt 文件(即 不会的名称/路径所说的文件作为参数),将用正确的信息替换该文件的模板部分。

I would rather not try to make any further commit/push, but use a filter driver in order, on checkout/update to be able to generate the right content for that version.txt file (i.e. with the right version string inside)

enter image description here

The smudge script, if it is able to recognized the content of a version.txt file (i.e. it won't have the name/path of said file as parameter), would replace a template section of that file with the right information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文