7

我使用命令发送了一个提交(名为“A commit”)以审查(Gerrit)git review

现在,我做了一个新的提交(名为“B 提交”),我也想将它发送给审查,但我不想重新发送“A 提交”。彼此之间没有依赖关系。

如何向 gerrit 发送特定提交的评论?

更新

$ git add --all


$ git status

# On branch delete_role
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   path/to/file.ext


$ git status

# On branch delete_role
nothing to commit (working directory clean)


$ git branch

*delete_role
 master


$ git log --graph --decorate --oneline -n13

* 531bd84 (HEAD, delete_role) commit 3
* df68f1a (master) commit 2
* 4ce2d8d commit 1
*   6751c7d (origin/master, origin/HEAD, gerrit/master)

提交“ df68f1a ”和“ 4ce2d8d ”是依赖的,它们已在先前的git review命令中发送,但提交“ 531bd84 ”属于新分支(delete_role),因为是一个新问题。

$ git review

You have more than one commit that you are about to submit.
The outstanding commits are:

531bd84 (HEAD, delete_role) commit 3
df68f1a (master) commit 2
4ce2d8d commit 1

我只想向Gerrit 发送531bd84 ”提交,而不是其他提交。

4

4 回答 4

9

在新分支中创建 B 提交。

在这个分支上时,使用git review它只会将这个分支的内容推送到 Gerrit。

这样,Gerrit 不会认为您的提交 B 需要您的提交 A,如果您愿意,您可以在提交 A 之前将您的提交 B 合并到工作分支

如果你的历史是这样的:

...-old(merged)-A(waiting for review)

你想要做的是:

...-old(merged)-A(waiting for review) <-master branch
       \B(new commit)                 <-new branch

然后,如果您在分支 B 上并使用git review,则除了提交 B 之外,它不会推送任何其他内容

如果您处于这种情况:

...-old(merged)-A(waiting for review)-B

,要实现我们想要的配置,你要做的是:

git log (Note the SHA1 of your B commit)
git reset HEAD^^^ (you go back in detched state three commits before, before the two you don't want to send)
git checkout -b Breview (you create a new branch there)
git cherry-pick +the SHA1 you noted (you copy your B commit on your new branch)
git checkout master (you return on your branch with the two commit)
git reset HEAD^--hard (you delete the B commit from this branch where you don't need it)

现在,您实现了想要的配置并推送您的 B 提交,您只需要执行以下操作:

git checkout Breview
git review

它只会提交你的 B 提交

于 2013-11-04T13:49:33.380 回答
4

分支是答案:

如果你还没有提交 A,那么在提交 A 之前,先创建分支 A,然后将你的代码提交到该分支并提交以供审核。然后,返回 master 并创建分支 B,提交到分支 B 并提交以供审核。这样可以确保没有依赖关系。

好的,现在假设您已经像这样在 master 中提交了所有内容:

M----A----B

这是您的日志:

commit b58fff12319d7ad1b1bc6ebcf4395d986a8ffac3
Author: 
Date:   Fri Nov 8 09:48:23 2013 +0800

    Change B

commit 99f249cdf2352ace3ca9ee8bf7a8a732f27b31eb
Author: 
Date:   Fri Nov 8 09:47:56 2013 +0800

    Change A

commit f091b7a4cc5c0532973c5bd401d2171f6fb735ec
Author: 
Date:   Fri Nov 8 09:47:30 2013 +0800

    Initial commit

我们想要的是这样的:

    A
  / 
 /
M 
 \
  \
   B

要获得此创建,请执行以下命令:

# Create two new branches from the point where the current Gerrit repo master is now
git branch A f091b7a4cc5c0532973c5bd401d2171f6fb735ec
git branch B f091b7a4cc5c0532973c5bd401d2171f6fb735ec
git checkout A # Create a branch to hold change A
git merge 99f249cdf2352ace3ca9ee8bf7a8a732f27b31eb
git log
commit 99f249cdf2352ace3ca9ee8bf7a8a732f27b31eb
Author: 
Date:   Fri Nov 8 09:47:56 2013 +0800

    Change A

commit f091b7a4cc5c0532973c5bd401d2171f6fb735ec
Author: 
Date:   Fri Nov 8 09:47:30 2013 +0800

    Initial commit
git checkout B 
git cherry-pick b58fff12319d7ad1b1bc6ebcf4395d986a8ffac3
git log
# Note the new sha1 hash as this is change could not be fast forwarded
commit d3aa1acc2b208115c7de78d5c9c4f6a906ece84a
Author: 
Date:   Fri Nov 8 09:48:23 2013 +0800

    Change B

commit f091b7a4cc5c0532973c5bd401d2171f6fb735ec
Author: 
Date:   Fri Nov 8 09:47:30 2013 +0800

    Initial commit

现在您有两个分支,每个分支都包含一个更改,将这些更改中的任何一个推送到 Gerrit 都会导致仅推送一个更改。

然后你可能想通过从那里删除提交来清理你的主人:

git checkout master
git reset --hard HEAD~2

特别针对更新问题:

git branch B 6751c7d 
git checkout B
git cherry-pick 531bd84 

您应该从 gerrit master 675c7d 创建分支,然后将您的提交 3 挑选到新分支中,然后您可以删除旧分支 delete_role

于 2013-11-05T00:31:51.347 回答
1

我看到它的方式是你有你工作的分支,然后你有提交 A 和下一个提交 B 也在同一个分支中。所以从逻辑上讲,它们并不相互依赖,但对于历史来说,这些变化是相互依赖的。因此,在第二个 B 可以合并之前,第一个提交 A 需要审核并合并到工作分支。

现在,当您将引用推送到审核时,Gerrit 已经通过更改 id 知道您推送的审核内容。如果您推送分支来审查,则只会发送新的提交,或者更新或重新定位的提交。

长话短说。Gerrit 知道什么是新的,什么已经在审查中。

于 2013-11-04T14:02:31.270 回答
1

推送提交“A”后,您可以重置本地分支并开始处理提交“B”。因为每次提交/更改都可以在被推送到审查分支后从 Gerrit 中签出。您可以在每个补丁集下载面板从 Gerrit 审查委员会获取命令。一个例子:

git fetch https://android.googlesource.com/kernel/tegra refs/changes/43/69243/2 && git checkout FETCH_HEAD

签出更改后,可以对其进行修改并作为新补丁集再次推送。所以你不必为每个提交使用本地分支。

于 2013-11-04T22:59:42.723 回答