Bitbucket 上的 Git 历史重写 [远程拒绝] HEAD -> 分支(拒绝预接收钩子)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26732339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git history rewrite on Bitbucket [remote rejected] HEAD -> branch (pre-receive hook declined)
提问by Rob Kielty
On Bitbucket, using the Bitbucket web interface, I sync'd a blessed repo with my own private fork in error. I wanted to rewrite history on the blessed repo to bring it back to the correct commit.
在 Bitbucket 上,使用 Bitbucket Web 界面,我错误地将一个有福的存储库与我自己的私有分支同步。我想在受祝福的 repo 上重写历史记录以将其带回正确的提交。
I cloned the blessed repo that contained my incorrect commits and locally ran
我克隆了包含我不正确提交的祝福仓库并在本地运行
git reset --hard HEAD~1
on the branch whose history was screwed up.
在历史被搞砸的分支上。
This brought the cloned repo back to the commit it was at before I screwed it up.
这将克隆的 repo 带回了它在我搞砸之前的提交。
I then went to push my repo back up to Bitbucket using
然后我去将我的回购推回 Bitbucket 使用
git push -f origin development
but got the following error
但出现以下错误
remote: permission denied to force push branch development
To [email protected]:blessed-repo/blessed-repo.git
! [remote rejected] HEAD -> development (pre-receive hook declined)
error: failed to push some refs to '[email protected]:blessed-repo/blessed-repo.git'
Why did I get this error and how can I make the git push
work?
为什么我会收到这个错误,我该如何git push
工作?
回答by Rob Kielty
In Bitbucket, it is possible to limit push powers broken-linkuse branch permissionsto prevent users from pushing to a branch directly.
在 Bitbucket 中,可以限制推送权限断开链接使用分支权限,以防止用户直接推送到分支。
From the above (old, no longer available) docs ...
从上述(旧的,不再可用)文档...
Users are free to interact with a branch in their local clone. When they attempt to push to the Bitbucket remote, users who aren't allowed to push to the branch receive a message that the remote rejected the push.
用户可以自由地与其本地克隆中的分支进行交互。当他们尝试推送到 Bitbucket 远程时,不允许推送到分支的用户会收到远程拒绝推送的消息。
You can see how this would be useful to enforce typical work flows.
您可以看到这对强制执行典型的工作流程有何用处。
To enable direct pushing to a branch on a repo
启用直接推送到 repo 上的分支
goto
去
Repo> Settings> Branch management> Prevent history re-writes (rebase) on these branches
回购>设置>分支管理>防止在这些分支上重写历史记录(rebase)
then on that page, remove the branch that you are pushing to.
然后在该页面上,删除您要推送到的分支。
This will then enable you run git push origin +HEAD
这将使您能够运行 git push origin +HEAD
Then you should re-add the branch to the list to prevent random pushes to the repo.
然后,您应该将分支重新添加到列表中,以防止随机推送到 repo。