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.

oberlies
  • 11,503
  • 4
  • 63
  • 110
Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
  • 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 again – Michael Oct 31 '19 at 04:38

4 Answers4

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.

Dženan
  • 3,329
  • 3
  • 31
  • 44
Brad
  • 5,492
  • 23
  • 34
  • 8
    This doesn't work: When pushing the commit of an old patch set, I get the error "no new changes". – oberlies Jun 26 '15 at 10:54
  • 1
    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. – geekofalltrades Jun 26 '15 at 19:44
  • 5
    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. – geekofalltrades Jun 26 '15 at 20:36
  • 13
    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. – Milimetric Sep 02 '16 at 02:40
  • @Brad, could you please incorporate the advice from @Milimetric's comment regarding `git commit --amend` to your answer? – Brian Cain Sep 19 '16 at 16:01
  • it's a wiki, anyone can edit :) And you should, if it improves the answer – Milimetric Sep 19 '16 at 21:37
  • 1
    Thank you @Milimetric! That's exactly what I needed. And reading your name under the helpful comment was a nice surprise :) – brightbyte Jul 21 '17 at 17:08
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).

dferenc
  • 7,918
  • 12
  • 41
  • 49
sbodd
  • 321
  • 2
  • 7
  • I think this is a valid answer then why this is -1 ? – AmitM Dec 05 '18 at 03:12
  • 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. – WesternGun Jul 07 '21 at 11:48
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
askb
  • 6,501
  • 30
  • 43
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

Royi
  • 1
  • 1