我在共享托管服务器上设置了一个存储库。我想从现在开始使用 git 将本地更改直接推送到我的共享主机,但尽管出现 ok 消息,我仍然看到文件没有任何更改:
在共享主机(远程服务器)上
初始化 git 仓库
cd public_html/.git
git init
git add .
git commit -m 'First commit'
在我的笔记本电脑上(本地服务器)
我将其克隆到本地计算机上的中央远程存储库
git clone ssh://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e38e86a38e878c8e828a8dcd918c" rel="noreferrer noopener nofollow">[email protected]</a>:15554/home/mydomain/public_html/.git
现在我有了远程存储库的工作副本 我只有一个名为“master”的分支。我可以看到它:
git branch
我在名称“origin”下添加远程存储库:
git remote add origin ssh://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bdd0d8fdd0d9d2d0dcd4d393cfd2" rel="noreferrer noopener nofollow">[email protected]</a>:15554/home/mydomain/public_html/.git
我可以列出远程存储库:
git remote
将显示:原点 在这个阶段我已经完成了我的工作再次提交我的更改(如上所述) 现在,我将更改推送回我的主存储库所在的远程服务器。
git push origin master
在共享主机(远程服务器)上
我设法通过将远程存储库转换为裸存储库来实现它:
git config --bool core.bare true
在我的笔记本电脑上(本地服务器)
我再次推送数据:
git push origin master
得到了
Compressing objects: 100% (30/30), done.
Writing objects: 100% (32/32), 663.98 KiB, done.
Total 32 (delta 21), reused 0 (delta 0)
To ssh://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b4d9d1f4d9d0dbd9d5ddda9ac6db" rel="noreferrer noopener nofollow">[email protected]</a>:15554/home/mdomain.ropublic_html/.git
a416e72..bb19005 master -> master
但是,当在浏览器中访问我的网址时,我仍然看不到更改。怎么了?
最佳答案
错误消息非常清楚,表明服务器无法更新当前 checkout 分支(master
)的工作树。
要解决此问题,您可以查看 how to convert your server's repo to a bare repo .
另一个选项(尽管我强烈建议不要这样做)是将服务器存储库的 git 配置中的 receive.denyCurrentBranch
设置为 ignore
或 warn
> 或 false
。
如果您想要做的是使用 git push 作为在服务器上部署新代码的方法,并且即使只有一个简单的存储库,您也需要一个工作树,那么您可以看看this答案我之前发布过,其中详细介绍了如何在服务器上 checkout 单独的工作树并设置一个接收后 Hook ,该 Hook 负责从裸存储库更新此工作树。
关于git 成功将更改推送到主存储库,但仍然看不到文件中的任何更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15751846/