简单的 git post-commit 钩子将提交的文件复制到某个文件夹
我想自动将提交的文件复制到某个文件夹,以便可以在浏览器中查看它们,但我想这样做而不必创建一个镜像主存储库的裸存储库(如图所示 此处),我希望这在提交时发生。
有没有简单的方法来创建一个钩子来读取已提交的文件并在实时网络服务器上复制/更新它们?
例如:我有一个名为 /example.com 的文件夹和一个 git 存储库。我希望当我在存储库中提交index.html时,/example.com中相应的index.html文件将被更新为所提交文件的内容
I would like to automatically copy the committed files to a certain folder so they can be viewed in a browser, but I would like to do this without having to create a bare repository that mirrors the main repository (as shown here) and I would like this to happen on commit.
Is there any simple way to create a hook that reads which files have been committed and copies them/updates them on a live webserver?
For example: I have a folder named /example.com and a git repository. I want that when I commit index.html in the repository, the corresponding index.html file from /example.com to be updated with the contents of the committed file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行此操作的一个好方法是创建一个运行 git checkout -f 的
post-commit
,并将工作树设置为 Web 服务器公开的目录,并且git 目录设置为开发存储库中的.git
目录。例如,您可以创建一个执行以下操作的.git/hooks/post-commit
文件:但是要小心 -
-f
意味着 git 可能会删除或覆盖使/example.com/
与您最近提交中的树匹配的文件。(请记住使
.git/hooks/post-commit
文件也可执行。)A good way of doing this is to create a
post-commit
that runsgit checkout -f
with the work tree set to the directory that is exposed by your web server and the git directory set to the.git
directory in your development repository. For example, you could create a.git/hooks/post-commit
file that did:Be careful with this, however - the
-f
means that git may remove or overwrite files to make/example.com/
match the tree in your most recent commit.(Remember to make the
.git/hooks/post-commit
file executable as well.)