Git branching / rebasing good practices

拥有回忆 提交于 2020-01-01 08:49:32

问题


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?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/2601967/git-branching-rebasing-good-practices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!