我有一台名为production
的服务器,从主分支检出了git源代码并运行。
此外,我还有一个被克隆了git仓库的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
之外,还有其他方法吗?
git pull OTHER_BRANCH
命令。 - Lasse V. Karlsengit push -f origin master
? - maciejwwwdevelopment
服务器实际上是一个代理,它从主裸仓库拉取。我主要的问题是production
有一个网络限制,防止它从其他服务器拉取。 - oshai