Revert to older patch set version via the Gerrit UI?
Asked Answered
A

4

45

If I have multiple patch set versions for one change in Gerrit, it seems like I can only submit the latest patch set version (because only that one has the necessary button). Is there an easy way to instead submit one of the old patch set versions of the same change, using only my web browser on that Gerrit instance?

I know that I can fetch the wanted version of the patch set from my git client and push it as yet another new patch set version on top, but I would like to avoid having identical patch set versions multiple times in the review and discussion around it.

Aba answered 6/7, 2012 at 5:11 Comment(1)
Maybe worth adding the use case: "Accidentally pushed rebase commit that otherwise was identical". Now the +2 approval is lost and need to pester colleagues to review againPenman
P
32

No, sorry, this is not currently possible. The design assumes that the most recent patch set is the one developers will review and test, and as such older patch sets can not be submitted. They also can not be reviewed/verified. If you want to use an older version of a patch set, you must re-submit it to make it the most recent patch set. To avoid no new changes error do git commit --amend and git will create a new sha1, which will be happily accepted by Gerrit as a new patch set.

Phosphoroscope answered 6/7, 2012 at 15:17 Comment(7)
This doesn't work: When pushing the commit of an old patch set, I get the error "no new changes".Zendejas
It's a little bit convoluted. You need to actually revert the changes introduced by the patchsets following the one you want, then amend those reversions to the review and resubmit. That will get you back to the state represented by the patchset that you want. You can probably accomplish this with the reflog, if you know what you're looking for, but I'll have to leave that to the true git wizards.Commanding
Here's something that works, although it might be a bit of a hack: find in the reflog the HEAD state of the latest patchset, call it X, and the HEAD state of the patchset you want to revert to, call it Y. Do git diff HEAD@{X} HEAD@{Y} | git apply --index. Now you have changes staged that undo all of the changes made in between Y and X. Do git commit --amend, then resubmit the review. You now have a new patchset that brings you back to the state of the desired patchset.Commanding
You don't need to jump through that many hoops. Just don't do anything and git commit --amend will create a new sha1 for the same commit. You can send this to gerrit and it will think it's a new patch.Eiser
@Brad, could you please incorporate the advice from @Milimetric's comment regarding git commit --amend to your answer?Mittiemittimus
it's a wiki, anyone can edit :) And you should, if it improves the answerEiser
Thank you @Milimetric! That's exactly what I needed. And reading your name under the helpful comment was a nice surprise :)Exigent
M
21

There is no proper way to do this using only Gerrit UI. Cherry-pick the specific "patch set" of the "change list" (e.g. if there are 15 patch sets in a Change List and want to revert back to patch set #8). Get the cherry-pick command from Gerrit UI for the required patch set.

Run that cherry-pick command, and use git commit --amend, then push your change. It will generate new patch set (for above example #16).

Matisse answered 19/2, 2018 at 12:2 Comment(2)
I think this is a valid answer then why this is -1 ?Gaffer
Just one note to make it clearer: create another branch from master, and use that cherry pick command you copied from Gerrit web, of the patchset you want; and then your new branch will be the state you want. Push to head ref, and you have a new patch set but with the same change id and so. Perfect. I didn't use commit amend.Carinacarinate
B
2

The only way I could do this was as follows (from the change refspec assuming you are in Gerrit revision "<change-no>/3" and want to go back to "<change-no>/1").

git review -d <change no>,1
git commit --amend  # modify something in the commit message
git review          # resubmit the changes, will submit to rev 1
Biller answered 29/6, 2022 at 2:58 Comment(0)
O
0

found a way to do it from Gerrit UI

  1. switch to older patch
  2. press edit
  3. change something in the patch (code/commit msg/anything)
  4. save changes

new PS will be created based on the old patch *you can edit again to revert the changes you made in step 3

Overcash answered 9/7, 2023 at 11:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.