简单的git post-commit hook将提交的文件复制到某个文件夹 [英] Simple git post-commit hook to copy committed files to a certain folder

查看:627
本文介绍了简单的git post-commit hook将提交的文件复制到某个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动将提交的文件复制到某个文件夹中,以便在浏览器中查看它们,但是我希望这样做,而不必创建反映主存储库的裸存储库(如这里),我希望在commit时发生。



有没有什么简单的方法来创建一个钩子,读取哪些文件已提交,并复制它们/更新它们在实时网络服务器上?



例如:我有一个名为/example.com和一个git存储库。我希望当我在存储库中提交index.html时,/example.com中相应的index.html文件将使用提交文件的内容进行更新。

解决方案一个好的方法是创建一个运行 git checkout -f post-commit 工作树设置为您的Web服务器公开的目录,并将git目录设置为开发库中的 .git 目录。例如,您可以创建一个 .git / hooks / post-commit 文件:

 #!/ bin / sh 
unset GIT_INDEX_FILE
export GIT_WORK_TREE = / example.com /
export GIT_DIR = / home / whoever / development / web-project / .git /
git checkout -f

不过要注意, -f 意味着git可以删除或覆盖文件以使 /example.com/ 匹配最近提交中的树。 .git / hooks / post-commit 文件的可执行文件。)

$($ p

b $ b

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

解决方案

A good way of doing this is to create a post-commit that runs git 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:

#!/bin/sh
unset GIT_INDEX_FILE
export GIT_WORK_TREE=/example.com/
export GIT_DIR=/home/whoever/development/web-project/.git/
git checkout -f

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.)

这篇关于简单的git post-commit hook将提交的文件复制到某个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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