Git代码审查:如何从多个提交中提交特定的提交

3
我在运行git review时遇到了以下问题:
git review
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:

2de3eef (HEAD -> AddingReleaseIndex) Adding index page for subrelease projects
d3dbc89 (Addingindex) Add index with submodules

Do you really want to submit the above commits?
Type 'yes' to confirm, other to cancel: no
Aborting.

我有许多分支,每个分支都实现了特定的功能。我只想发送HEAD(2de3eef)上的提交进行审查,不想发送其他内容。

我找到了一篇文章,它说我可以使用 git cherry-pick 将选定的提交移动到另一个分支并从另一个分支发送它进行审查。但我不想通过另一个分支发送它,我想通过同一个分支发送它,因为它是关于特定功能的。

我该如何解决这种情况?


d3dbc89 提交是你的吗?为什么 2de3eef 提交基于它?为什么你不想推送它? - Marcelo Ávila de Oliveira
这个 commit 是我的,但它在另一个分支上。每个分支都是一个特性分支,只有相关的特性应该放在该分支上。d3dbc89 是与添加发布索引相关的特性,d3dbc89 与添加发布索引不相关。 - FlyingAura
2个回答

3

看起来你有类似这样的内容:

.. ---A     <= master
       \
        B   <= feature1
         \
          C <= feature2

这种方式(基于提交B的提交C),如果您将提交C推送到Gerrit,则必须同时推送提交B。 您需要按照以下方式工作:

        B <= feature1
       /
.. ---A   <= master
       \
        C <= feature2

提交 C 必须基于提交 A。feature1 和 feature2 分支必须并行工作。


2

你可以使用git rebase -i来重新排列你的提交,使你想要提交的提交不依赖于任何其他你不想提交的提交。


1
你能详细说明一下吗? - FlyingAura
如果我拥有提交并只想将它们作为单独的补丁提交(这不会提交没有更改的补丁),我会将每个审查放入自己的分支中,并对以下操作进行git checkout。然后使用git rebase -i master n+1,然后重复执行rebase -i n+1 n+2等操作,直到达到要提交审核的提交所在的分支。对于每个rebase -i n n+1,您需要按照它们需要被重新基于的顺序从上到下添加pick <commitId>,其中顶部的pick应该是主分支,而最后一个commitId是该分支的提交以供审核。 - Trevor McCasland

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接