我和我的同事最近实现了 git,并且刚刚尝试实现 rebase。因此,我们有一个本地克隆的远程 master
分支,我有一个名为 changes
的本地(和远程)分支。在本地,我们已经做了一些更改
工作,所以它看起来像这样:
master: A
\
changes: B-C-D
因此,通过来自其他地方的不相关 merge ,master
得到了升级,因此我们:
master: A-E
\
changes: B-C-D
所以,我做了一个 rebase :
git checkout changes
git rebase E (via a tag)
因此,在我的本地存储库中,我有:
master: A-E
\
changes: B-C-D
所以,我尝试进行推送,但得到:
remote: error: denying non-fast-forward refs/heads/changes (you should pull first)
似乎,传统观点是强制 push 我的更改
工作回到原点/更改
:
git push -f origin changes
回复如下:
remote: error: denying non-fast-forward refs/heads/changes (you should pull first)
To /opt/git/online.git
! [remote rejected] changes -> changes (non-fast-forward)
error: failed to push some refs to '/opt/git/online.git'
所以,我现在有点困惑。我假设工作流程是在对本地更改
进行 rebase 后,我可以使origin/changes
对齐。我是不是理解错了?
最佳答案
使用 push -f
命令请求您的 Git 客户端尝试推送引用,即使它不是当前远程分支的后代。但是,上游存储库仍然可以拒绝该请求。
您可以通过更改上游存储库 config
文件中的配置选项来允许此操作:
[receive]
denyNonFastforwards = false
Git book关于此选项有以下说法:
receive.denyNonFastForwards
If you rebase commits that you’ve already pushed and then try to push again, or otherwise try to push a commit to a remote branch that doesn’t contain the commit that the remote branch currently points to, you’ll be denied. This is generally good policy; but in the case of the rebase, you may determine that you know what you’re doing and can force-update the remote branch with a-f
flag to your push command.
关于git - 如何将重新定位的分支恢复到原点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19042731/