来自更新后挂钩的 Git 推送失败 - X 不是存储库
我正在尝试设置一个中央存储库,当它从我的本地计算机推送到另一个存储库时,它将自动推送到另一个存储库。我已经在谷歌上搜索了好几天了,我已经尝试了我能找到的所有命令组合,但没有运气。
设置: 我首先将中央存储库创建为裸机,然后将其作为非裸机克隆到第二台计算机。我将第二台计算机作为远程计算机(称为“www”)添加到第一台计算机。我确认我可以从第一台机器手动执行“git push www master”,它将通过 SSH 更新第二台机器。然后,我通过 HTTP 将存储库克隆到我的本地开发计算机。我可以很好地从地方推到中央。
我的更新后钩子的当前形式:
#!/bin/bash
cd /var/git_repos/site.git
unset $(git rev-parse --local-env-vars)
branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$branch" == "master" ];
then
echo "Pushing $branch to www..."
env -i git push www master
fi
exec git update-server-info
我从各种 SO 和博客文章中拼凑了这个。从第一台机器的 CLI 手动执行时工作正常(“cd /var/git_repos/site.git/hooks; ./post-update”),但执行时收到错误消息“www 不是 Git 存储库”作为一个钩子。
输出:
$ git push
Password:
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 264 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Pushing master to www...
remote: fatal: 'www' does not appear to be a git repository
remote: fatal: The remote end hung up unexpectedly
To https://[email protected]/site.git
e3d3a1d..103c819 master -> master
谁能告诉我我做错了什么?
编辑:我发现我最初的问题是 site.git 上的权限设置不完全正确。解决了这个问题后,我又遇到了一个新问题。
新输出:
$ git push
Password:
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 332 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: I am apache <---- Output of "whoami" for debugging
remote: Pushing master to www...
remote: ssh: connect to host 192.168.1.79 port 22: Permission denied
remote: fatal: The remote end hung up unexpectedly
To https://[email protected]/site.git
29d504c..f14f201 master -> master
我尝试将以下内容添加到我的 /etc/sudoers 文件中,但没有成功:
apache ALL=NOPASSWD: /usr/bin/ssh
I am trying to setup a central repository that will automatically push to another repository when it is pushed to from my local machine. I have been Googling for several days now and I have tried every command combination I could find with no luck.
The setup:
I first created the central repository as a bare and then cloned it to the second machine as a non-bare. I added the second machine as a remote, called "www", to the first machine. I confirmed that I could execute "git push www master" manually from the first machine and it will update the second via SSH. I then cloned the repository to my local development machine via HTTP. I can push from local to central just fine.
My post-update hook in its current form:
#!/bin/bash
cd /var/git_repos/site.git
unset $(git rev-parse --local-env-vars)
branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$branch" == "master" ];
then
echo "Pushing $branch to www..."
env -i git push www master
fi
exec git update-server-info
I have cobbled this together from various SO and blog posts. It works fine when executed manually from the CLI of the first machine ("cd /var/git_repos/site.git/hooks; ./post-update") but I get the error message "www is not a Git repository" when executed as a hook.
The output:
$ git push
Password:
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 264 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Pushing master to www...
remote: fatal: 'www' does not appear to be a git repository
remote: fatal: The remote end hung up unexpectedly
To https://[email protected]/site.git
e3d3a1d..103c819 master -> master
Can anyone tell me what I am doing wrong?
Edit: I have figured out that my initial issue was that the permissions on site.git were not entirely set correctly. Having fixed that problem, I have a new problem.
New output:
$ git push
Password:
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 332 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: I am apache <---- Output of "whoami" for debugging
remote: Pushing master to www...
remote: ssh: connect to host 192.168.1.79 port 22: Permission denied
remote: fatal: The remote end hung up unexpectedly
To https://[email protected]/site.git
29d504c..f14f201 master -> master
I have tried adding the following to my /etc/sudoers file with no luck:
apache ALL=NOPASSWD: /usr/bin/ssh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是尝试推送到未知远程时出现的错误。尝试:
检查
并确保 www 已正确定义,同时检查
www 也应该在那里。
打印钩子本身所有命令的输出并比较输出。
This is the error you get when trying to push to an unknown remote. Try:
Check
and make sure that www is properly defined, also check
www should be there as well.
Print the output of all commands from the hook itself and compare the output.
我建议将
www
更改为您要推送到的远程存储库的完整 URL。另外将master
更改为master:master
可能会有所帮助。I would suggest changing the
www
to the full url of the remote repo you are pushing to. Additionally changingmaster
tomaster:master
might be of help.我认为您没有
看到人们试图从不同的存储库进行 git pull 的钩子。您只需执行与当前存储库相关的所有命令。所以你不必这样做。
同样,不要这样做:
删除
env -i
Don't do
I think you saw the hooks where people were trying to do a git pull from a different repo. You are just doing all the commands relative to the current repo. So you don't have to do that.
Similarly, don't do:
remove the
env -i