How to revive a closed commit for cherry-picking on Gerrit?

957 views Asked by At

Background

I am using Gerrit. One commit C has been merged into branch dev and needed to be cherry-picked into branch main. One of my colleagues have tried to cherry pick using below command.

git checkout main
git cherry-pick `C`

He pushed in Gerrit and after some review he messed up and end up abandoning the commit C on branch main. Now, when I am trying freshly to cherry pick the same commit. Gerrit is rejecting the commit to push on branch main, saying that the commit is already closed. As a policy we can not push as new commit rather we must cherry pick for keeping branch histories.

To ssh://gerrit.company.net:29417/project
 ! [remote rejected]     HEAD -> refs/for/main (change https://gerrit.company.net/open/426535 closed)
error: failed to push some refs to 'ssh://[email protected]:29417/project'

How can I deal with this situation?

2

There are 2 answers

2
Marcelo Ávila de Oliveira On

You could try to change the Change-Id of your change:

  1. Amend your local commit (commit --amend)

  2. Remove the Change-Id and save

  3. Push again to Gerrit

0
Richard Fearn On

Gerrit is rejecting the push because there is a change (426535) that (a) has the same Change-Id, (b) is for the same branch (main), and (c) is closed.

From https://gerrit-review.googlesource.com/Documentation/error-change-closed.html:

If the change for which you wanted to upload a new patch set was abandoned and your new changes overcome the reasons for abandoning this change you may want to restore the change in the Gerrit Web UI (browse the abandoned change in the Gerrit Web UI and click on the 'Restore Change' button). Afterwards the push should succeed and a new patch set for this change will be created.