15

Is it possible to fetch an existing patchset (that has not been merged into my local machine), change and push it as a new Patch Set?

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
Alexandre Santos
  • 8,170
  • 10
  • 42
  • 64

3 Answers3

31

@Uncletall put all the steps there and the link, the only thing is that you should not delete the changeId and you should do a git commit --amend. I am giving him a +1.

It should be like this

  1. On Gerrit, go to the review, select "checkout", on the Download field as opposed to "pull", "cherry-pick", or "patch", then copy the command.

  2. On the git project paste the copied link from above

    This will create a detached head, which is a branch with no name (I've been through the desert on a horse with no name, It felt good to be out of the rain.)

  3. Name that horse! git checkout -b new_branch_name

  4. Change what you want and do a git add on the files you want.

  5. Do git commit --amend and keep the same Change-Id.

  6. Push your changes:

    git push origin <new_branch_name>:refs/for/<thatgerritbranchyouwanttochange>

Community
  • 1
  • 1
Cindy Langdon
  • 611
  • 6
  • 12
  • 1
    I think you mean `git checkout -b `. I also then had to amend author information prior to the push since the previous patch was created by someone else: `git commit --amend --author "myself "` – Gareth Nov 06 '14 at 10:37
  • why not use `HEAD` instead of creating a new local branch that is not worth for anything (gerrit sadly only keeps a single commit per change any ways) – erikbstack Nov 01 '17 at 11:13
5

Consult Trying out a Change in the official documentation.

Here is what you do:

  1. Checkout the change as described in the documentation
  2. Create a local branch from the FETCH_HEAD
  3. Modify your code
  4. Commit the change using git --amend and remove the Change-Id in the commit message
  5. A new Change-Id will automatically be added and this will result in a new Change Set
  6. Push your change for review and Gerrit will see it as a new Change Set

As pointed out by @magnus-bäck, I was describing how to create a new Change-Set. If you want to add a new Patch Set to the current review you should NOT remove the Change-Id.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
uncletall
  • 6,609
  • 1
  • 27
  • 52
  • This will create a new _change_, but I think what's being asked for is being table to create a new patch set _on the original change_. Removing the "remove the Change-Id line" item from the list above will address this. One could also mention that it's assumed that a Change-Id line is present in the original commit message. If it isn't, https://gerrit-review.googlesource.com/Documentation/user-upload.html#push_replace describes what to do. – Magnus Bäck Jun 30 '14 at 05:34
5

Just follow the below steps:

  1. cherry-pick your patch (from gerrit UI) to your machine.
  2. Modify the content and run git add <modified file>.
  3. Amend the last commit using git commit --amend that pops up a COMMIT-EDITMGS window. Save it accordingly.
  4. Push your change to gerrit using git push origin HEAD:refs/for/branch_name

    It will create a new patch set.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
love
  • 1,000
  • 2
  • 16
  • 35