Git Post Receive Hook:将当前工作分支更新到登台服务器 [英] Git Post Receive Hook: update current working branch to staging server
问题描述
echopost hook is running!
while read oldrev newrev ref
do
echo$ ref
完成
unset $(git rev-parse --local -env-vars)
cd ../staging/bikereport
git fetch
git pull origin $ ref
echoPost receive finsihed
然而,我并没有看到服务器上的更改,而远程返回Already up-to-date这让我觉得它是从法师或其他人那里拉出来的?
这不是一个很好的解决方案,但我们是一个 单个项目。一个理想的解决方案是将每个分支保存到登台服务器中的一个新目录中,然后每次推送只更新该目录。
cd ../staging/bikereport
git fetch
<注意:你的git目录是不是你的 staging / bikereport
repo。
它仍然是 钩子运行的地方。
您需要将 GIT_DIR
设置为 /full/path/ofstaging/bikereport/.git
(可以肯定的是,将 GIT_WORK_TREE
设置为 / full / path / ofstaging / bikereport
),以便从 repo运行的命令可以正常工作。
您需要取消设置 GIT_INDEX_FILE
!
请参阅为什么不设置GIT_WORK_TREE在post-commit钩子中工作?以获取更多详细信息。
您的钩子应该从以下开始:
#!/ 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 fetch
Beware: 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:将当前工作分支更新到登台服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!