git 当还有第二个较新的评论时,如何修改 Gerrit 中的评论问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12487791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:37:52  来源:igfitidea点击:

How to amend review issues in Gerrit when there is a second newer review also

gitgerrit

提问by Adrian Cornish

Still trying to learn how to use Gerrit and its process. Steps I did where

仍在努力学习如何使用 Gerrit 及其过程。我在哪里做的步骤

  1. Push first change1to gerrit for review to HEAD:refs/for/develop
  2. Work on something else on same branch and push change2to gerrit for review to HEAD:refs/for/develop
  1. 首先推change1送到 gerrit 以供到 HEAD:refs/for/develop
  2. 在同一分支上处理其他事情并推change2送到 gerrit 以供到 HEAD:refs/for/develop

Both commits have gerrit Change-ID lines

两个提交都有 gerrit Change-ID 行

So now I want to address issue for change1so I did

所以现在我想解决问题change1所以我做了

git checkout -b change1 <change 1's commit id>

Made my changes and committed (adding the Change-ID to the commit message)

进行我的更改并提交(将更改 ID 添加到提交消息)

git add .
git commit

Now when I do

现在当我做

git push origin HEAD:refs/for/develop

I get

我得到

 ! [remote rejected] HEAD -> refs/for/develop (squash commits first)
error: failed to push some refs to 'ssh://[email protected]:29418/CommunicationsLibrary'

How do I fix issues in stacked reviews and post it to gerrit without having to create yet another review?

如何修复堆积评论中的问题并将其发布到 gerrit 而无需创建另一条评论?

回答by Trevor Powell

When you have dependent reviews in Gerrit (that is, one change in review which is dependent on an earlier change which is simultaneously in review), and you need to make modifications to the earlier change, you effectively have to resubmit both changes (since the second change becomes dependent on a different "parent" commit)

当您在 Gerrit 中有依赖(即中的一个变更依赖于同时在中的较早更改),并且您需要对较早的更改进行修改时,您实际上必须重新提交这两个更改(因为第二个更改取决于不同的“父”提交)

So the situation is that you have two commits in a single branch off of the main development branch, like this:

因此,情况是您在主开发分支的单个分支中有两个提交,如下所示:

o master
\
 o Commit A (in review, requires change)
 o Commit B (in review, no changes required)

What I generally do in this situation is to make the changes requested of Commit A in a third commit. Our commit graph now looks like this:

在这种情况下,我通常做的是在第三次提交中进行提交 A 请求的更改。我们的提交图现在看起来像这样:

o master
\
 o Commit A (in review, requires change)
 o Commit B (in review, no changes required)
 o Commit C (modifications to Commit A)

Now I do git rebase -i masterand reorder Commit C to come after Commit A but before Commit B, and then squash it into Commit A. The commit graph now looks like this:

现在我做git rebase -i master并重新排序 Commit C 在 Commit A 之后但在 Commit B 之前,然后将其压缩到 Commit A 中。 提交图现在看起来像这样:

o master
\ 
 o Commit A' (Commit A, incorporating the changes from Commit C)
 o Commit B' (the same changes made in Commit B, but applied to Commit A' instead of A)

Finally, git review(or whatever command you use to submit changes to gerrit) to re-submit both commits to Gerrit.

最后,git review(或您用来向 gerrit 提交更改的任何命令)将两个提交重新提交给 Gerrit。

It's because of complications like this that most people strongly recommend working on each distinct change in a separate branch and then squashing down into a single commit before submitting to Gerrit, rather than needing to deal with these types of situations where you have dependent changes being reviewed at the same time.

正是因为这样的复杂性,大多数人强烈建议在单独的分支中处理每个不同的更改,然后在提交给 Gerrit 之前将其压缩为单个提交,而不是需要处理这些类型的依赖更改正在的情况同时。

回答by xshoppyx

I think your problem is related to the fact that the amendment to the 1st commit has the second commit as a dependency now. This is what I would personally do but there may be a better way. I look at it as you want to rebase the way your commits are and you are dealing with the last 3. So run 'git rebase -i HEAD~3'. This allows you to rebase the last 3 commits via switching the order or melding them to each other. You should be aware that it lists the commits in oldest-first order. Here's an example:

我认为您的问题与第一次提交的修正现在将第二次提交作为依赖项有关。这是我个人会做的,但可能有更好的方法。我看着它,因为你想以你的提交方式重新设置并且你正在处理最后 3 个。所以运行'git rebase -i HEAD~3'。这允许您通过切换顺序或将它们相互融合来重新设置最后 3 个提交。您应该知道它以最旧的顺序列出提交。下面是一个例子:

git log is as follows:

git日志如下:

commit info:......

提交信息:......

message: foo2

消息:foo2

commit info:......

提交信息:......

message: bar1

消息:bar1

commit info:......

提交信息:......

message: foo1

消息:foo1

After running the above command an editor should pop up with the following:

运行上述命令后,应弹出一个编辑器,其中包含以下内容:

pick foo1.

选择 foo1。

pick bar1.

选择 bar1。

pick foo2.

选择 foo2。

(This is assuming your second foo change didn't change any of the files that bar1 changed as this might not work and if you did do that you should have amended the commit anyway.) Then change the list to this:

(这是假设您的第二个 foo 更改没有更改 bar1 更改的任何文件,因为这可能不起作用,如果您这样做了,您应该无论如何都应该修改提交。)然后将列表更改为:

pick foo1

选择 foo1

fixup foo2

修复 foo2

pick bar1

选择栏1

After that you will have foo1 and foo2 squashed into one commit and bar1 will be the commit following. Then I would run 'git reset --soft HEAD~1' resetting the newest commit, followed by a 'git commit --amend' which allows you to change the commit message for the first review and make sure to include the change-id. Then try your push. After that you should have a new patch set up, and all the files the second change was will be modified and still in your working directory.

之后,您将 foo1 和 foo2 压缩为一个提交,而 bar1 将是以下提交。然后我会运行 'git reset --soft HEAD~1' 重置最新的提交,然后是 'git commit --amend',它允许您更改第一次的提交消息并确保包含更改 ID . 然后试试你的推。之后,您应该设置一个新补丁,第二次更改的所有文件都将被修改,并且仍在您的工作目录中。

回答by Haoyi Mike

call

称呼

commit --ammend

instead for your 2nd change

而不是你的第二次改变

回答by CheStar

just git commit --amend then git review

只是 git commit --amend 然后 git review

回答by WUJ

The situation is exactly like @Trevor explained. rebase -iis a good way to do when you have this condition.

情况与@Trevor 解释的完全一样。rebase -i当你有这种情况时,这是一个很好的方法。

Personally, I use this command as well but with a little bit different:

就个人而言,我也使用此命令,但有一点不同:

1. Use --fixup and --autosquash

1. 使用 --fixup 和 --autosquash

you have two commits:

你有两个提交:

old commit
new commit

when you want to change old commit, then

当你想改变旧的提交时,那么

 git commit --fixup <old_commit_id>

then rebase with autosquash,

然后用 autosquash 变基,

git rebase -i --autosquash <commit_id_before_old_commit>

If it's unclear of my comments, you can check the detail in: https://fle.github.io/git-tip-keep-your-branch-clean-with-fixup-and-autosquash.html

如果不清楚我的评论,您可以查看以下详细信息:https: //fle.github.io/git-tip-keep-your-branch-clean-with-fixup-and-autosquash.html

OR

或者

2. Take advantage of Gerrit

2. 利用 Gerrit

After you commit two changes, you will have two open-reviewschange on you GUI.

提交两次更改后,您的 GUI上将有两次开放更改。

Then go to your "old change", select download -> checkoutthis change, actually after you checkout, you will go to a branch for this change, then fix your code, amend, rebase, push ... like what you do as usual.

然后转到您的“旧更改”,选择下载-> 结帐此更改,实际上在您结帐后,您将转到此更改的分支,然后修复您的代码,修改,rebase,推送......就像您所做的一样通常。

回答by Bhoopendra Dandotiya

I tried with these attempts

我尝试了这些尝试

  1. did git rebase -i master
    it didn't work
  2. then last what I did, I took backup of files. Deleted the whole project. then cloned it again. Paste files in the required folder from backup and then recommitted again and then pushed. It worked .
  1. git rebase -i master
    它没有用
  2. 然后最后我做了什么,我备份了文件。删除了整个项目。然后再次克隆它。将备份中的文件粘贴到所需文件夹中,然后再次重新提交,然后推送。有效 。