[英]Why is `git push --force-with-lease` failing with "rejected ... stale info" even when my local repo is up to date with remote?
I'm trying to force push a rebase of a feature branch to a remote repository.我正在尝试将功能分支的变基强制推送到远程存储库。 To be a bit safer, I'm trying to use
--force-with-lease
to make sure no other changes have happened in the branch since I last fetched it.为了更安全一点,我尝试使用
--force-with-lease
来确保分支中没有发生其他更改,因为我上次获取它。
This is failing for reasons I don't understand:由于我不明白的原因,这失败了:
$ git branch
* my-branch
master
$ git push --force-with-lease origin my-branch -u
To gitlab.com:example/my-project.git
! [rejected] my-branch -> my-branch (stale info)
error: failed to push some refs to 'git@gitlab.com:example/my-project.git'
I tried a fetch to see if my local cache had somehow gotten out of sync:我尝试获取以查看我的本地缓存是否以某种方式不同步:
$ git fetch
$ git push --force-with-lease origin my-branch -u
To gitlab.com:example/my-project.git
! [rejected] my-branch -> my-branch (stale info)
error: failed to push some refs to 'git@gitlab.com:example/my-project.git'
I tried simplifying the push command a bit:我尝试稍微简化一下 push 命令:
$ git push --force-with-lease
To gitlab.com:example/my-project.git
! [rejected] my-branch -> my-branch (stale info)
error: failed to push some refs to 'git@gitlab.com:example/my-project.git'
I tried limiting the check to my branch:我尝试将检查限制在我的分支:
$ git push --force-with-lease=my-branch:origin/my-branch
To gitlab.com:example/my-project.git
! [rejected] my-branch -> my-branch (stale info)
error: failed to push some refs to 'git@gitlab.com:example/my-project.git'
As you can see, it fails the same way every time.如您所见,它每次都以相同的方式失败。
Why is my push failing, and how do I fix it?为什么我的推送失败,我该如何解决?
If you just have done your rebase and don't want to start over again please run git remote prune origin
.如果您刚刚完成了 rebase 并且不想重新开始,请运行
git remote prune origin
。 If you then run git push --force-with-lease
again, it will work.如果您然后再次运行
git push --force-with-lease
,它将起作用。
In this case it turned out that the problem was that the remote branch had been deleted, but there was still a copy of it in my local repo. 在这种情况下,事实证明问题是远程分支已被删除,但在我的本地仓库中仍然有它的副本。 Fetch doesn't delete local copies by default, which is why it had no effect.
默认情况下,Fetch不会删除本地副本,这就是它无效的原因。
Adding the --prune
option to my initial git pull
(before doing my rebase) corrects this problem. 在我的初始
git pull
添加--prune
选项(在执行我的rebase之前)纠正了这个问题。
在我的情况下,一个简单的git fetch
然后再次推送解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.