如何在git中的post-receive hook中处理分支上的文件 [英] how to process files on a branch in post-receive hook in git
本文介绍了如何在git中的post-receive hook中处理分支上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个远程服务器,我在其上创建了一个裸露的git存储库。
我想创建一个钩子,以便给定脚本在任何给定分支上收到的最新代码上运行。
我知道 post-receive
钩子可以用于它。然而,我想要执行以下操作:
- 获取收到代码的分支。
- 在临时位置签出代码并对其执行操作。
如何执行上述操作?
解决方案
- 对于1),您有一个阅读分支名称(通过stdin)的示例:
无法检测到Git post的分支对于2),您需要适当地设置GIT_WORK_TREE:
管理网站使用git + post-receive hook:错误推送更改
请参阅 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];然后
git --work-tree = / path / under / root / dir / live-site / checkout -f $ branch
echo'Changes push live。'
fi
if [dev==$ branch];然后
git --work-tree = / path / under / root / dir / dev-site / checkout -f $ branch
echo'推送到dev的变化'
fi
完成
I have a remote server on which I have created a bare git repository.
I would like to create a hook so that a given script is run on the latest code received on any given branch.
I know the post-receive
hook can be used for it. However I want to do the following:
- Get hold of the branch on which code was received.
- Checkout the code in a temp location and run an operation on it.
How do I do the above?
解决方案
- For 1), you have an example of reading the branch name (through stdin):
"Not able to detect branch from Git post-receive hook" - For 2), you need to set GIT_WORK_TREE appropriately:
"Managing website using git + post-receive hook: error pushing changes"
See both techniques combined in "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
这篇关于如何在git中的post-receive hook中处理分支上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文