首页 > 解决方案 > `git pull --rebase` 在功能分支上合并原始/主更改

问题描述

我已经阅读了许多关于 的文章和问题git pull --rebase,但我不确定它如何适用于我的情况 - 特别是关于共享/公共分支

最初设定:

远程主站已更新

--rebase考虑到我已经提交并推送它们,可以这样做吗?

根据 Atlassian 的更新 ,一旦您的分支被推送(公开),请不要使用rebase

git rebase 的黄金法则是永远不要在公共分支上使用它。

https://www.atlassian.com/git/tutorials/merging-vs-rebasing#the-golden-rule-of-rebasing

标签: gitgithubbitbucket

解决方案


Is the --rebase ok to do given that I have already made commits and pushed them?

Maybe.

If other people have checked out your branch (and perhaps even made their own local commits), rebasing has the potential to cause a nightmare of merge conflicts. However, rebasing is often regarded as good housekeeping on projects to keep the history cleaner. When you rebase just before a merge, you are essentially injecting fast-forwardable commits. Without the rebase, you'll merge into your branch first, then push back, which can create messy situations if any individual commit of yours needs to be reverted.

No Rebase

(main)   A - - - B - - - C - - - D     E
          \                       \   /
(feature)   F - - - G - - - H - - - I

Rebase

(main)   A - - - B - - - C - - - D                   E
                                  \                 /
(feature)                          F - - - G - - - H

推荐阅读