Do not rebase commits that you have pushed to a public repository.
If you follow that guideline, you’ll be fine. If you don’t, people will hate you, and you’ll be scorned by friends and family.
在这里,我在工作中创建了一个本地分支 feature-xyz,并将其推送到远程存储库。我将其 pull 到另一台计算机上,做了更多工作并推送。回到工作岗位,我 pull 了 Twig 。经过几次提交后,我重新调整了我的分支。现在我已经完成了 feature-xyz 并希望将其推送到远程存储库,但这显然失败并显示以下消息:
$ git push origin feature-xyz
To git@<url>:<repo>.git
! [rejected] feature-xyz -> feature-xyz (non-fast-forward)
error: failed to push some refs to 'git@<url>:<repo>.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
显然, pull 远程分支会产生各种冲突。因此,我决定删除远程分支:
git推送原点:feature-xyz
并重新创建它:
git push origin feature-xyz
但是我想知道是否有更好的工作流程,不涉及删除远程分支?
最佳答案
那就不要 rebase 了。 merge 。
即,不要将 feature-branch
rebase 到 anotherBranch
之上。将 anotherBranch
merge 到 feature-branch
。
请注意,删除远程分支或 push --force
同一分支是相同的。
在这两种情况下,您都发布了新的 SHA1,重写了历史记录,这对于之前提取过 feature-branch
的其他人来说可能会带来不便。
关于Git 如何对我已经推送的(个人)分支进行 rebase ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13047333/