Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git部署,其中也可以从服务器提交更改_Git_Deployment - Fatal编程技术网

Git部署,其中也可以从服务器提交更改

Git部署,其中也可以从服务器提交更改,git,deployment,Git,Deployment,我有一个关于平面文件CMS的网站,我想通过Git进行部署。我希望能够从我的本地机器在网站上工作,并推送到实时服务器,但我还需要能够通过CMS的web管理面板编写新内容,并将这些内容返回到我的机器到我的开发环境中 做这件事最好的方法是什么?我试图在我的机器和服务器上都安装repo,并将服务器设置为本地repo的远程服务器。当我试图将更改推送到服务器时,出现了一个错误 remote: error: refusing to update checked out branch: refs/heads/m

我有一个关于平面文件CMS的网站,我想通过Git进行部署。我希望能够从我的本地机器在网站上工作,并推送到实时服务器,但我还需要能够通过CMS的web管理面板编写新内容,并将这些内容返回到我的机器到我的开发环境中

做这件事最好的方法是什么?我试图在我的机器和服务器上都安装repo,并将服务器设置为本地repo的远程服务器。当我试图将更改推送到服务器时,出现了一个错误

remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.

我可以随时更改远程设备的配置以允许这样做,但我觉得可能有更好的解决方案,因为默认情况下不允许这样做。通过Git实现这一点的最佳方法是什么?理想情况下,通过管理面板所做的更改将自动提交,但这可能要求太多。

如果您使用服务器的SSH密钥进行git repo,您应该能够从服务器提交/推送,这与部署密钥方法不同。但不建议这样做,因为你可能会因为制造冲突而陷入麻烦。因为解决服务器上的冲突可能是一项繁忙的任务

您需要3个存储库才能运行此功能:

  • 一个空存储库,它将是其他两个存储库的远程存储库
  • 一种定期的本地回购协议,您可以在该协议中执行工作并从远程推送/拉送
  • 服务器上的常规repo是您的部署站点,它从远程进行升级,并在您从cms进行更改时推送
  • 您可以从任何现有回购中创建裸回购,如下所示:

    git clone --bare source destination
    
    GIT_DIR=/path/to/bare.git
    GIT_WORK_TREE=/path/to/work/tree
    git status
    
    更新

    这篇博文解释了一种有趣的方法,其中部署目录不是Git存储库:

    尽管工作树本身不是Git存储库,但您仍然可以运行如下Git命令:

    git clone --bare source destination
    
    GIT_DIR=/path/to/bare.git
    GIT_WORK_TREE=/path/to/work/tree
    git status
    
    就我个人而言,我使用了一种更复杂的方法,在部署中我有两个站点:mysite.com和dev.mysite.com,因此我的post-receive-hook需要更多的逻辑来知道要升级哪个部署,这取决于我推送到的分支名称:


    我有这种设置,并且工作得相当好。谢谢你的帮助。当我在管理面板中进行更改时,是否可以让它提交并自动推送到裸回购?这将大大简化我的工作流程。我可能说得有点太早了。我曾经设置我的裸存储库,以便在服务器上自动签入我的部署路径。然而,这使得我无法将更改从服务器提交回repo,除非我遗漏了什么,因为工作树本身不是git repo。你能给我更多关于如何设置的详细指导,以便我可以从任何一方提交吗?你仍然可以通过破解一些环境变量来提交,请参阅我的更新。我还添加了我个人使用的另一种方法,部署目录本身就是存储库。感谢您的帮助。我最终在服务器上克隆了repo。我从该存储库的子目录提供服务,因此实际的.git文件夹没有被提供。我认为这应该和从一个根本不属于回购协议的文件夹中提供服务一样好。