Git 分支/ rebase 良好实践

标签 git dvcs branch git-branch

我有以下场景:

3个分支:
- 大师
- MyBranch 从 Master 分支出来,目的是开发系统的新功能
- MyBranchLocal 从 MyBranch 分支为我的分支的本地副本

MyBranch 正在被其他开发人员(他们正在开发与我相同的功能)反对和 push 。

作为 MyBranch 分支的所有者,我想通过 rebase 使其与 Master 保持同步。我还需要将我对 MyBranchLocal 所做的更改与 MyBranch merge 。

这样做的好方法是什么?

到目前为止我尝试过的几个可能的场景:

一.
1. 提交更改到 MyBranchLocal
2. 将 MyBranch rebase 到 Master
3. 将 MyBranchLocal rebase 到 MyBranch
4.将MyBranch与MyBranchLocal merge

二.
1. 提交更改到 MyBranchLocal
2. 将MyBranch与MyBranchLocal merge
3. 将 MyBranch rebase 到 Master
4. 根据 MyBranch 对 MyBranchLocal 进行 rebase

三.
1. 提交更改到 MyBranchLocal
2. 将 MyBranch rebase 到 Master
3.将MyBranch与MyBranchLocal merge
4. 根据 MyBranch 对 MyBranchLocal 进行 rebase

我已经知道方案 III 似乎将提交历史搞得一团糟,可能会重复提交。

你的经验是什么?您建议使用哪些方案来最大程度地减少 merge 工作并保持历史记录干净?

最佳答案

个人建议。这个专注于拥有直接的提交历史,并在“更具体”的分支上失败(你最好弄乱你的本地分支而不是功能分支)。

  1. 提交对 MyBranchLocal 的更改
  2. 根据 MyBranch 对 MyBranchLocal 进行 rebase
  3. 将 MyBranch 与 MyBranchLocal merge (应该快进)- MyBranch = Local
  4. 根据 Master 对 MyBranch 进行 rebase
    1. (可选)将 Master 与 MyBranch merge (也应该快进)
  5. 根据 MyBranch 对 MyBranchLocal 进行 rebase

关于Git 分支/ rebase 良好实践,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2601967/

相关文章:

Mercurial 文件ID

git - 如何在不创建本地分支的情况下创建远程 Git 分支?

mercurial - Mercurial 全局变更集 ID 的分配

git - 我在哪里? *(没有分支)

git - 执行 git reset 后的匿名分支

html - 在 html 文件中自定义嵌入式 Git Gist 文本大小

git - 是否可以在 git 中 merge 分支并保留历史记录?

git - 如何自定义 git rebase --interactive 提交消息的格式?

git - 我可以 pull 一个尚未 merge 的 pull 请求吗?

git - 从 StarTeam 迁移到分布式源代码管理