Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.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 pull——通过git push重新基址_Git - Fatal编程技术网

模拟git pull——通过git push重新基址

模拟git pull——通过git push重新基址,git,Git,我有一个名为production的服务器,它的git源代码是从主分支签出并执行的。 此外,我还有一个开发服务器,带有git repo的克隆,在那里我可以修改代码。 我想同步源代码development->production 我最初的想法是在production服务器上运行git pull--rebase,以获取最新提交的文件。但是,由于网络限制(防火墙等),生产部门无法联系开发部门,但另一种方法可行:开发部门可以从生产部门拉/推 当我试图推动时,我得到了以下信息: + git push ori

我有一个名为
production
的服务器,它的git源代码是从主分支签出并执行的。 此外,我还有一个
开发
服务器,带有git repo的克隆,在那里我可以修改代码。
我想同步源代码
development->production

我最初的想法是在
production
服务器上运行
git pull--rebase
,以获取最新提交的文件。但是,由于网络限制(防火墙等),
生产部门无法联系
开发部门
,但另一种方法可行:
开发部门
可以
生产部门拉/推

当我试图推动时,我得到了以下信息:

+ git push origin master
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'.      
我的理解是,为了推送更改,我应该配置
receive.denycurrentbrance
,然后在推送之后在生产主分支上执行
git reset--hard
。此外,这将覆盖生产中未提交的更改。
有没有更安全的方法?例如,有时有人可能使用ssh连接到生产机器,并直接在那里更改代码。我希望在这种情况下我的命令会失败。另一个例子是,生产服务器有一些未跟踪的文件,我担心这些文件会被覆盖/删除


除了在生产服务器上进行git重设之外,还有其他方法吗?

评论中提到的两条建议:

  • 推送到
    生产
    上的另一个分支,
    git pull。分支机构名称
    生产
    机器上
  • 生产
    机器上设置额外的裸回购。由于git是分布式的,所以服务器可以在任何机器上,对于我的网络限制来说,将它放在
    生产上就很简单了

  • 我最终实现了#1。

    推送到生产服务器上的另一个分支,然后用ssh连接到它并使用
    git-pull-OTHER#u-branch
    。可能
    git-Push-f origin master
    ?我对您的设置感到有点困惑,为什么您要尝试从开发服务器拉到/拉到它,您的主服务器(可能是裸机)在哪里充当代码中心主机的存储库?如果您没有这个,我建议您创建它(根据您的设置猜测,您应该在prod上创建),然后Dev可以推/拉到它,prod可以从中拉it@nick-我不想让我的问题复杂化,但我的实际设置更复杂。我称之为
    development
    的服务器实际上是一个从主存储库提取的代理。我的主要问题是,
    生产
    有一个网络限制,阻止它从其他服务器上拉。明白了。您仍然可以在生产环境中设置一个裸存储库(git打算以这种方式分发,所以不会有问题),从您的设置的声音来看,这应该可以工作吗?