繁体   English   中英

通过 git push 模拟 git pull --rebase

[英]emulating git pull --rebase by git push

我有一个名为production的服务器,其中 git 源代码从 master 分支检出并执行。 此外,我有一个带有 git repo 克隆的development服务器,我可以在其中进行代码修改。
我想同步源代码development -> production
我最初的想法是在production服务器上运行git pull --rebase来获取最新的提交文件。 然而,由于网络限制(防火墙等), production无法联系development但相反的工作方式: development可以从production git pull/push
当我尝试推送时,我收到以下消息:

+ 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.denyCurrentBranch然后在推送之后在生产主分支上执行git reset --hard 此外,这将覆盖生产中未提交的更改。
有没有更安全的方法来做到这一点? 例如,有时有人可能会通过 ssh 连接到生产机器并直接在那里更改代码。 我更喜欢我的命令在这种情况下会失败。 另一个例子是生产服务器有一些我害怕覆盖/删除的未跟踪文件。

除了生产服务器上的git reset --hard之外,还有其他方法吗?

评论中提到的几个建议:

  1. 推送到production另一个分支git pull . BRANCH_NAME production机器上的git pull . BRANCH_NAME
  2. production机器上设置额外的裸仓库。 由于 git 是分布式的,服务器可以在任何机器上,对于我的网络限制情况,将它放在production上很简单。

我最终实现了#1。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM