问题描述
因此,我有一个登台服务器设置,我想要做的是当有人推到非主分支时更新登台服务器的目录。我当前的post-receive hook如下所示:你的 staging / bikereport repo。
它仍然是 钩子运行的地方。
您需要将 GIT_DIR 设置为 /full/path/ofstaging/bikereport/.git (可以肯定的是,将 GIT_WORK_TREE 设置为 / full / path / ofstaging / bikereport ),以便从 repo运行的命令可以正常工作。
您需要取消设置 GIT_INDEX_FILE !
请参阅以获取更多详细信息。
您的钩子应该从以下开始:
#!/ bin / sh
unset GIT_INDEX_FILE
export GIT_WORK_TREE = / full / path / ofstaging / bikereport /
export GIT_DIR = / full / path / ofstaging / bikereport / .git /
So, I have a staging server setup, and what I would like to do is when someone pushes to a non master branch update what the staging server's directory. My current post-receive hook looks like:
echo "post hook is on the run!" while read oldrev newrev ref do echo "$ref" done unset $(git rev-parse --local-env-vars) cd ../staging/bikereport git fetch git pull origin $ref echo "Post receive finsihed"However I am not seeing the changes I would like on the server, and remote returns "Already up-to-date" which makes me think it's pulling from Master or something?
This isn't an elegant solution, but we are a very small team working on a single project. An ideal solution would be to save every branch to a new directory within the staging server and then update only that directory per push.
解决方案cd ../staging/bikereport git fetchBeware: your git directory is not your staging/bikereport repo.
It is still the one where the hook is running.You need to set GIT_DIR to /full/path/ofstaging/bikereport/.git (and to be sure, set GIT_WORK_TREE to /full/path/ofstaging/bikereport) in order for commands run from that repo to work.
And you need to unset GIT_INDEX_FILE!See "Why doesn't setting GIT_WORK_TREE work in a post-commit hook?" for more details.
You hook should start with:
#!/bin/sh unset GIT_INDEX_FILE export GIT_WORK_TREE=/full/path/ofstaging/bikereport/ export GIT_DIR=/full/path/ofstaging/bikereport/.git/
这篇关于Git Post Receive Hook:将当前工作分支更新到登台服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!