我有一个远程服务器,我在上面创建了一个裸 git 存储库。
我想创建一个钩子,以便给定的脚本在任何给定分支上收到的最新代码上运行。
我知道post-receive
可以使用钩子来实现它。但是我想做以下事情:
- 找到收到代码的分支。
- 在临时位置检出代码并对其运行操作。
我该如何做到以上?
- 对于 1),您有一个读取分支名称的示例(通过 stdin):
"无法从 Git post-receive hook 检测分支 https://stackoverflow.com/questions/5973795/not-able-to-detect-branch-from-git-post-receive-hook"
- 对于2),您需要适当设置GIT_WORK_TREE:
"使用 git + post-receive hook 管理网站:推送更改时出错 https://stackoverflow.com/questions/10902551/managing-website-using-git-post-receive-hook-error-pushing-changes/10903184#10903184"
请参阅“中结合的两种技术”Git 后接收多个远程分支和工作树 http://blog.ekynoxe.com/2011/10/22/git-post-receive-for-multiple-remote-branches-and-work-trees/":
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "master" == "$branch" ]; then
git --work-tree=/path/under/root/dir/live-site/ checkout -f $branch
echo 'Changes pushed live.'
fi
if [ "dev" == "$branch" ]; then
git --work-tree=/path/under/root/dir/dev-site/ checkout -f $branch
echo 'Changes pushed to dev.'
fi
done
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)