git rebase master 然后推送原始分支导致非快进错误

发布于 2024-12-28 07:14:58 字数 766 浏览 2 评论 0原文

我正在尝试处理我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贱贱哒 2025-01-04 07:14:58

变基后无法推送。由于历史记录不同,提交现在具有不同的 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.

樱桃奶球 2025-01-04 07:14:58

对您的问题的简短回答:您可以通过将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文