7

我正在尝试在我的 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.

如何在不强制服务器接受的情况下重新设置基准?

4

2 回答 2

9

变基后你不能推动。提交现在具有不同的 SHA1,因为它们的历史不同。如果更新的 ref 不包含其祖先中的旧 ref,则这是一个潜在的有害操作,git 不会允许它。

如果您不想强制,您唯一的替代方法是合并。

如果您独自工作并且不需要让其他人提交到这个分支,那么强制并不是那么糟糕。

于 2012-01-20T23:09:42.697 回答
5

对您的问题的简短回答:您可以通过将 master 重新定位到 featureA(但不要推送)来做相反的事情,然后将 featureA 重置到该点。

这实际上是从 master 到 featureA 上挑选提交,缺点是你最终会在两个分支上重复提交。它将解决您眼前的问题(如果这是您的意图),但从长远来看,您不应该重新定位已经推送到远程分支的提交。您方案中的最佳解决方案实际上是合并。

于 2012-01-20T23:14:08.620 回答