尝试推送到远程 Amazon EC2(Ubuntu Linux)实例时出现错误。我已授予所有相关目录和文件完全权限。我尝试使用 post-receive 钩子将项目移动到我的生产目录/var/www/myapp
:
$ git push prod-server master
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 292 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: error: cannot run hooks/post-receive: No such file or directory
To prod-server:/home/ubuntu/myapp/myapp.git
8944048..a445d1d master -> master
我的接收后文件(位于裸存储库:)/home/ubuntu/myapp/myapp.git/hooks/
:
#!/bin/bash
while read oldrev newrev ref
do
branch=`echo $ref | cut -d/ -f3`
if [ "prod-server" == "$branch" -o "master" == "$branch" ]; then
git --work-tree=/var/www/myapp/ checkout -f $branch
echo 'Changes pushed to Amazon EC2 PROD-SERVER directory!'
fi
if [ "test" == "$branch" ]; then
git --work-tree=/var/www/myapp/test/ checkout -f $branch
echo 'Changes pushed to Amazon EC2 PROD-SERVER test directory!'
fi
done
答案1
看起来问题在于脚本没有放在正确的位置。本地存储库和服务器上post-receive
的输出是什么?git remote -v
ls -l /home/ubuntu/myapp/myapp.git/hooks
关于脚本本身的一些提示: