在等待公关的同时工作

我正在做一个项目,我提交了我的第一个拉请求,当我在等待的时候,我想继续我的项目建设工作,从我工作的合并,仍然悬而未决。现在我有:

*master
user_story_1

user_story_1有一个开放式请求。

现在我试图创建一个新的分支 user_story_2,在那里我可以继续我在 user_story_1的工作。我如何在 Git 中做到这一点,而不会陷入任何冲突或影响挂起的合并?

21020 次浏览

Create a new branch from master for each of your stories/features.

Before merging each branch back, either merge master into that branch or rebase your branch onto master. The latter has my preference, but in the end the outcome is the same.

You are going to get conflicts, there is no way around that. However, you want to solve conflicts in your branch; not in master. This way, you can test your branch after resolving the conflicts before merging it into master.

I'm assuming you want to start the new user_story_2 branch on top of the work you've done in user_story_1. Here's the workflow I use in this sort of scenario:

  1. Open Pull Request for user_story_1:

      * (user_story_1)
    *
    /
    * (master)
    *
    *
    
  2. Create new branch user_story_2 based on user_story_1:

    $ git checkout -b user_story_2 user_story_1
      * (user_story_1, user_story_2)
    *
    /
    * (master)
    *
    *
    
  3. Work on the new branch:

      * (user_story_2)
    *
    * (user_story_1)
    *
    /
    * (master)
    *
    *
    
  4. Pull Request gets merged:

      * (user_story_2)
    *
    * | (master)
    |\|
    | * (user_story_1)
    | *
    |/
    *
    *
    *
    
  5. Delete old branch:

      * (user_story_2)
    *
    * | (master)
    |\|
    | *
    | *
    |/
    *
    *
    *
    
  6. Rebase new branch onto master:

      * (user_story_2)
    *
    /
    * (master)
    |\
    | *
    | *
    |/
    *
    *
    *
    

My preferred workflow for this:

  1. On branch master, git checkout -b user_story_1.
  2. Make changes to user_story_1.
  3. Open PR for user_story_1.
  4. On branch user_story_1, git checkout -b user_story_2.
  5. Make changes to user_story_2.
  6. Once user_story_1 gets merged into master, switch to user_story_2 and do git rebase -i master.
  7. This should show you a list of commits on user_story_2 that you want to include in the rebase. Delete the top few commits that came from user_story_1.
  8. The rebase should complete cleanly unless master was updated with other changes. Now you have user_story_2 rebased on master and only having its commits.