Git 如何对我已经推送的(个人)分支进行 rebase ?

标签 git git-rebase

我读了git book但不知何故忘记了rule上面写着:

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/

相关文章:

git - 如何 rebase merge 但保留 merge 提交

git - 为什么要签署 Git 标签?

git - 为什么 git-svn 因信号 13 而失败?

Mac 版 Git 安装程序 : Why is/usr/local/git/bin in my PATH?

python - Git 博客 - 鹈鹕模板在新部署的博客中消失,但存在于本地主机中

git diff 重命名/move 和修改的文件但跳过重命名/move 和相同的文件

Git 挤压 merge 还是 git 强制推送?

git - 需要 git rebase -Ignore-all-space 来保留我的空间

git - 我怎样才能从远程标签 rebase 到本地主人

git - 标签可以在 git filter-branch 和 rebase 之后自动移动吗?