在提交之前提交给Gerrit之后如何提交额外的提交?

时间:2017-08-07 00:15:38

标签: git gerrit

我在提交之前提交给Gerrit之后尝试提交一个额外的(无关的)提交。我在两个不同的分支上创建了上一个和当前的提交。以下是工作流程的示例:

  1. git checkout -b <branch-1>
  2. git add folder1/*
  3. git commit -m "Added folder1."
  4. git review
  5. 提交给Gerrit并输出包括评论链接在内的信息。之后,我开始研究另一个(再次,无关的)变化:

    1. git checkout -b <branch-2>
    2. git add folder2/*
    3. git commit -m "Added folder2."
    4. git review
    5. 正是在这一点上,我遇到了以下情况:

      You are about to submit multiple commits. This is expected if you are
      submitting a commit that is dependent on one or more in-review
      commits. Otherwise you should consider squashing your changes into one
      commit before submitting.
      
      The outstanding commits are:
      373ea8b (HEAD -> branch-2) Added folder2.
      e626f4c (branch-1) Added folder1.
      
      Do you really want to submit the above commits?
      Type 'yes' to confirm, other to cancel: n
      Aborting.
      

      如何避免这种冲突?

1 个答案:

答案 0 :(得分:0)

问题是你根据第一个提交了第二次提交:

A             <= origin/branch
 \ 
  \-- B       <= branch-1
       \
        \-- C <= branch-2

要处理不相关的分支,你应该与这些独立的提交“并行”工作:

  /-- B <= branch-1
 /
A       <= origin/branch
 \
  \-- C <= branch-2

第一次提交:

git checkout -b <branch-1> origin/<branch>
git add folder1/*
git commit -m "Added folder1."
git review

第二次提交:

git checkout -b <branch-2> origin/<branch>
git add folder2/*
git commit -m "Added folder2."
git review