簡體   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