git rebase master 然后推送原始分支导致非快进错误
我正在尝试处理我的 featureA 分支,同时使其与 master 分支保持同步。
的场景
git clone ssh://xxx/repo
git checkout -b featureA
$ git add file.txt
$ git commit -m 'adding file'
$ git push origin featureA
这是同时将几个新提交推送到原始主机
git checkout master
git pull origin master
git checkout featureA
git rebase master
git push origin feature A
To ssh://xxx/repo
! [rejected] featureA -> featureA (non-fast-forward)
error: failed to push some refs to 'ssh://xxx/repo'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
,如何在不强制服务器接受它的情况下进行变基?
I am trying on working on my featureA branch while keeping it up-to-date with the master branch.
Here is the scenario
git clone ssh://xxx/repo
git checkout -b featureA
$ git add file.txt
$ git commit -m 'adding file'
$ git push origin featureA
meanwhile a couple new commits where pushed to origin master
git checkout master
git pull origin master
git checkout featureA
git rebase master
git push origin feature A
To ssh://xxx/repo
! [rejected] featureA -> featureA (non-fast-forward)
error: failed to push some refs to 'ssh://xxx/repo'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
How can I rebase without forcing the server to accept it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
变基后无法推送。由于历史记录不同,提交现在具有不同的 SHA1。如果更新后的引用不包含其祖先中的旧引用,则这是一个潜在有害的操作,并且 git 不允许这样做。
如果您不想强迫,唯一的选择就是合并。
如果您独自工作并且不需要其他人致力于此分支,那么强制并不是那么糟糕。
You can't push after rebasing. The commits now have different SHA1s as their history is different. If the updated ref does not contain the old ref in it's ancestry, it's a potentially harmful operation and git won't allow it.
Your only alternate is to merge if you don't want to force.
Forcing is not so bad if you are working alone and don't need to have others committing to this branch.
对您的问题的简短回答:您可以通过将 master 重新设置为 featureA 的基础(但还不要推送)来执行相反的操作,并将 featureA 重置到该点。
这实际上是从 master 到 featureA 的提交的优选,缺点是您最终会在两个分支上得到重复的提交。它将解决您眼前的问题(如果这是您的意图),但从长远来看,您不应该对已经推送到远程分支的提交进行变基。您的场景中最好的解决方案实际上是合并。
A short answer to your question: you can do the reverse by rebasing master against featureA (but don't push yet), and reset featureA to that point.
This is actually cherry picking the commits from master onto featureA, the downside is that you will end up with duplicate commits on two branches. It will solve your immediate problem (if that's your intention) but in the long run you should not be rebasing commits that have already been pushed to a remote branch. The best solution in your scenario is actually to merge.