Git 分支/变基良好实践

发布于 2024-08-28 07:56:44 字数 860 浏览 10 评论 0原文

我有以下场景:

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

MyBranch 的本地副本正在被其他开发人员(正在开发与我相同的功能)重新基础并推送。

作为 MyBranch 分支的所有者,我希望通过变基使其与 Master 保持同步。我还需要将对 MyBranchLocal 所做的更改与 MyBranch 合并。

有什么好的方法可以做到这一点?

到目前为止我尝试过的几种可能的情况:

I.
1. 将更改提交到 MyBranchLocal
2. 针对 Master 重新设置 MyBranch
3. 根据 MyBranch 重新设置 MyBranchLocal 的基础
4. 将 MyBranch 与 MyBranchLocal

II 合并。
1. 将更改提交到 MyBranchLocal
2. 将 MyBranch 与 MyBranchLocal 合并
3. 针对 Master 重新设置 MyBranch
4. 根据 MyBranch

III 重新设置 MyBranchLocal 的基础。
1. 将更改提交到 MyBranchLocal
2. 针对 Master 重新设置 MyBranch
3. 将 MyBranch 与 MyBranchLocal 合并
4. 针对 MyBranch 重新调整 MyBranchLocal

我已经知道场景 III 似乎会严重扰乱提交历史记录,可能会重复提交。

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

I have a following scenario:

3 branches:
- Master
- MyBranch branched off Master for the purpose of developing a new feature of the system
- MyBranchLocal branched off MyBranch as my local copy of the branch

MyBranch is being rebased against and pushed to by other developers (who are working on the same feature as I am).

As the owner of the MyBranch branch I want to keep it in sync with Master by rebasing. I also need to merge the changes I make to MyBranchLocal with MyBranch.

What is a good way to do that?

Couple of possible scenarios I tried so far:

I.
1. Commit change to MyBranchLocal
2. Rebase MyBranch against Master
3. Rebase MyBranchLocal against MyBranch
4. Merge MyBranch with MyBranchLocal

II.
1. Commit change to MyBranchLocal
2. Merge MyBranch with MyBranchLocal
3. Rebase MyBranch against Master
4. Rebase MyBranchLocal against MyBranch

III.
1. Commit change to MyBranchLocal
2. Rebase MyBranch against Master
3. Merge MyBranch with MyBranchLocal
4. Rebase MyBranchLocal against MyBranch

I already know that scenario III seems to be messing the commit history up a lot, potentially duplicating commits.

What is your experience? What scenarios do you recommend to minimize the merging effort and keep the history clean?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜尕妞 2024-09-04 07:56:45

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

  1. 提交对 MyBranchLocal 的更改
  2. 将 MyBranchLocal 与 MyBranch 合并
  3. 将 MyBranch 与 MyBranchLocal 合并(应该快进) - MyBranch = Local
  4. Rebase MyBranch against Master
    1. (可选)将 Master 与 MyBranch 合并(也应该快进)
  5. 针对 MyBranch Rebase MyBranchLocal

My personal suggestion. This one is focused on having a straight commit history, and failing on the "more specific" branches (you'd better mess up your local branch than the feature branch).

  1. Commit change to MyBranchLocal
  2. Rebase MyBranchLocal against MyBranch
  3. Merge MyBranch with MyBranchLocal (should be fast forward) - MyBranch = Local
  4. Rebase MyBranch against Master
    1. (optional) Merge Master with MyBranch (also should be fast forward)
  5. Rebase MyBranchLocal against MyBranch
此岸叶落 2024-09-04 07:56:45

我在链接到Linus电子邮件后发现了这个问题。根据电子邮件 - 在某些公共网站上发布历史记录后,您不应该重新设置基准,因为您可能会破坏其他人的历史记录。因此,对 MyBranchLocal 进行变基是可以的,但对 MyBranch(与其他开发人员共享)则不行。

I found this question after link to Linus email. According to email - you shouldn't rebase after you published your history in some public site, because you could destroy other people history. So, rebase for MyBranchLocal is OK, but for MyBranch (shared with other developers) is not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文