设置--work tree和push-to-deploy-post-receive钩子时git日志不匹配
我通过在设置--work tree和push-to-deploy-post-receive钩子时git日志不匹配,git,git-post-receive,git-bare,Git,Git Post Receive,Git Bare,我通过在/home/ubuntu/push to deploy/test.git上设置一个--bare目录,将其用作我的远程设备,并在--bare中添加一个hooks/post receive,如下所示: #!/bin/bash while read oldrev newrev ref do branch=`echo $ref | cut -d/ -f3` if [ "production" == "$branch" -o "master" == "$branch" ]; then
/home/ubuntu/push to deploy/test.git上设置一个--bare
目录,将其用作我的远程设备,并在--bare
中添加一个hooks/post receive
,如下所示:
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "production" == "$branch" -o "master" == "$branch" ]; then
git --work-tree=/var/www/test/ checkout -f $branch
sudo chown -R ubuntu:www-data /var/www/test
echo 'Changes pushed to Amazon EC2 PROD.'
fi
done
chmod -R g+s /var/www/test
当从我的本地主机推送到这个新的远程设备时,这非常有效。post receive
脚本按其应有的方式执行,内容更新按其应有的方式反映在/var/www/test
目录中。唯一的问题是,我的git日志/var/www/test
内部与我的本地主机根本不匹配。这是工作树的正常行为吗?如果是这样,我可以做些什么来保留这个推送部署功能,并且仍然将我的git日志和内容复制到生产目录
同时
当我的内容复制到生产目录(/var/www/test
)时,所有的文件所有权都被改写为ubuntu:ubuntu
,这使得www-data
无法运行。我在我的post receive
中放了一行,在每次接收后更新所有权,但是否有其他方法(更好的方法)可以做到这一点
更新
确保将www-data
保留为组的方法是如下设置目录的guid:
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "production" == "$branch" -o "master" == "$branch" ]; then
git --work-tree=/var/www/test/ checkout -f $branch
sudo chown -R ubuntu:www-data /var/www/test
echo 'Changes pushed to Amazon EC2 PROD.'
fi
done
chmod -R g+s /var/www/test
这会将其设置为目录的当前组,因此如果您希望它是www-data
,请确保在发出该命令之前将该组设置为www-data
谢谢您可以将环境变量GIT_DIR
设置为/home/ubuntu/push to deploy/test.GIT
和:
- 做你的
git--worktree=/var/www/test/checkout-f$branch
- 或者在
/var/www/test/
在这两种情况下,将考虑正确的索引
委员会确认:
刚刚做了一个chmod-rg+s/var/www/test
,现在正在运行
git-log--git-dir=/home/ubuntu/push-to-deploy/test.git
从/var/www/test
执行时应该可以正常工作。致命:无法识别的参数:--git-dir=/home/ubuntu/push-to-deploy/test.git对不起,我的意思是git---git-dir=/home/ubuntu/push-to-deploy/test.git-log
,然后,我是否应该在/var/www/test/.git/config
中添加一个选项,将git dir
更改为/home/ubuntu/push to deploy/test.git
,这样我就不必为每个这样的命令指定--git dir
选项了?请注意,简单地用cut-d/
拆分ref name是不太正确的:如果有一个ref的形式是refs/tags/master/v2
,例如,cut
将提取字段3,该字段将是master
。在这种特殊情况下可能没问题,但一般来说,您应该只测试“$ref”==refs/heads/master
例如。在这种情况下,这听起来很有效,但是如果我的生产服务器上有多个git repo呢?@sadmove那么您需要一些脚本/包装器来封装要运行的git命令,同时将git_DIR
设置为正确的repo。第二个问题有什么建议吗我的op?nvm的一部分-刚刚做了一个chmod-rg+s/var/www/test
,现在它正在工作