Git:更新后挂钩,运行需要访问存储库中所有文件的脚本
我现在遇到了一些困境,因为我需要一个脚本来运行,每当远程存储库更新时(即,每当有人运行 git Push),从存储库中的文件构建包。然后,这些包被放置到 git 服务器上的一个目录中,该目录通过 HTTP 公开给客户端以供将来使用。
问题是,我不确定如何在更新后挂钩中访问存储库中的文件。
如果有人能够提供一些见解,我们将不胜感激。
I'm running into a bit of dilemma at the moment in that I need a script to run whenever the remote repository is updated (ie, whenever someone runs git push) that builds packages from the files in the repository. These packages are then placed into a directory on the git server that's exposed to clients over HTTP for future use.
The problem is, I'm not sure how to access the files in the repository in the post-update hook.
If anyone can give some insight, it would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您可能想使用 post-receive 挂钩而不是 post-update。根据 githooks(5) 手册页,接收后取代更新后。
也就是说,你的钩子脚本是在 .git/hooks 子目录中执行的,所以如果你做一个简单的操作,
你的脚本就在 git 存储库的工作树中。例如,这里有一个小脚本,可确保每当您推送到存储库时远程 git 存储库的工作树都会更新:
请注意,您需要取消设置 GIT_DIR 环境变量;它是自动设置的,只要设置了,所有 git 命令都将在该目录中运行 - 无论您 cd 到哪里。
First of all, you might want to use the post-receive hook instead of post-update. According to the githooks(5) man page, post-receive supersedes post-update.
That said, your hook script is executed in the .git/hooks subdirectory, so if you do a simple
your script is in the working tree of the git repository. For instance, here's a tiny script which makes sure that the working tree of the remote git repository is updated whenever you push to the repository:
Note that you need to un-set the GIT_DIR environment variable; it's automatically set, and as long as its set all git commands will be run in that directory - no matter where you cd'ed to.
如果您的远程存储库是裸露的共享存储库,则没有文件的副本。
您可以更改此设置,然后您只需运行自动结帐即可。
如果您打包 hte 文件,最好也将存储库放在单独的目录中,
我使用以下内容来达到您指定的确切目的,
这里是向我展示如何设置它的博客文章
http://toroid.org/ams/git-website-howto
这是我的下面的简要注释
在存储库外部创建一个目录并将工作树放在那里,然后使其不再是一个裸存储库,以便有文件的副本,然后在运行打包脚本之前运行
If your remote repsitory is a bare shared repo, then there is no copy of the files.
you can change this, and then you'll just have to run an auto checkout.
if your packaging hte files, best to have the repo in a seperate directory too
I use the following for the exact purpose you've named
here is the blog post that showed me how to set it up
http://toroid.org/ams/git-website-howto
here are my abbrieviated notes below
make a directory outside the repo and put the working tree there, then make it no longer a bare repo so there is a copy of the files, then run a before you run your packaging script