当receive.denyCurrentBranch设置为updateInstead并且receive.denyNonFastForwards设置为true时,下面的行为对我来说似乎不正确。以下是重现该场景的步骤。 步骤1-设置远程仓库(远程主机):
git config --global receive.denyCurrentBranch updateInstead
git config --global receive.denyNonFastForwards true
mkdir /tmp/hello
cd /tmp/hello
git init
echo hello > hello.txt
git add . && git commit -m "hello.txt"
步骤2 - 创建2个克隆(本地主机):
git clone ssh://REMOTEIP/tmp/hello /tmp/hello1
git clone ssh://REMOTEIP/tmp/hello /tmp/hello2
第三步 - 从克隆1提交更改
cd /tmp/hello1
echo hello1 > hello1.txt
git add . && git commit -m "hello1.txt"
git push
目前为止,服务器工作树中包含了预期的 hello1.txt 文件。
步骤4:尝试从克隆2强制推送提交
cd /tmp/hello2
echo hello2 > hello2.txt
git add . && git commit -m "hello2.txt"
git push
远程主机拒绝我的推送,并提示我本地没有的工作内容,这是正确的。现在我强制推送。
git push --force
远程服务器再次拒绝并显示错误:拒绝非快进的refs/heads/master(您应该先拉取)
由于推送被拒绝,我预计服务器的工作树不包含任何被拒绝的更改。但是,服务器的工作树已更新以删除hello1.txt并创建hello2.txt。推送被拒绝但实际上并没有。
当更新钩子(而不是pre-receive钩子)拒绝更改时,我也注意到相同的行为(不正确)。