I have accidentally pushed a change to gerrit that should have been pushed as a draft. Now I'd like to unpublish the change back to a draft.
Pushing it again to refs/drafts/* doesn't work as it isn't changed.
Update:
I followed the suggestions of mvp and HiB; I abandoned the change, amended the commit message (removing the change-id, letting the post-commit hook generate a new change-id) and pushed it again. This resulted in a 'new' draft change. At first it looks OK, but history etc. isn't preserved of course. Not a big issue, but not the clean solution I'm looking for.
Once a change is published you cannot set it back to draft, but you may create new draft patch sets for a published change.
Related
Is there a way to delete a patch set in Gerrit? I accidentally pushed a file with a password in it to my change. I removed the file in another patch set but the file is still visible in the patch set history. I attempted to find a way to delete that particular patch set but the only thing I could find on how to do this was the following documentation...
https://gerrit-documentation.storage.googleapis.com/Documentation/2.8/cmd-review.html
which shows a delete option but that option is no longer available in later versions.
I ended up just checking out the latest patch set, creating a new branch, deleting the current change in gerrit and pushing the change from the new branch which removes the old patch sets but it seems a bit cumbersome.
No, you can't delete a patch set in Gerrit, but it's possible to delete the whole change. If you do not see the "Delete change" option, it's because you don't have permission to do that.
There are two permissions to control this, see the Gerrit documentation:
Delete Own Changes
Delete Changes
Last but not least, in these cases, it's better to simply change the password instead of trying to remove it from the repository. It's better safe than sorry.
A colleague sent me a Gerrrit code review "draft" (I suppose via "refs/drafts/master" instead of "refs/for/master") and then left on holiday. Without downloading the patch and submitting it myself, how can I promote his draft to a full regular code-review so I can approve it & submit it for merging?
I think this is a similar question, but it's for git-review, not Gerrit. Also I'm interested in doing it from the Gerrit web GUI if at all possible. And I don't see a "Publish" button on my Gerrit web GUI for that draft. (And currently it doesn't say anything about merge conflicts, as long as I hurry....)
If I click on the "Patch Sets" link in the top right of the GUI, this is what I see:
In the top left it says "Change 58358 - Draft", and in the middle of the window it shows this:
Only the change owner can publish a draft patch set. Using the UI's cherry-pick option as described in other answers won't work because the cherry-pick implementation preserves the draft status on the new change or patch set.
As far as I know the only way to force the change into NEW state is to manually download the commit and push a new patch set using refs/for/master instead of refs/drafts/master.
Note that if you're not rebasing the change onto a new parent at the same time, you might need to slightly edit the commit message to make gerrit accept it. Otherwise it'll reject with no new changes.
If your colleague add you as reviewer, you can. You can cherry-pick this commit.
Click on download link at the right-top corner, and there are aliases for commands above.
But as you updated your question, you don't want to check out and manually push or cherry pick to master branch. You can use cherry-pick\merge button on ui, if you are confident in this mr, and it should be on master branch. Also you can publish this commit for other reviewers.
p.s. updated (you can cherry-pick, merge, publish via UI)
Do the following procedure:
1) Go to the draft change page
2) Click on Cherry Pick button
3) Write "master" in the Cherry Pick to Branch field
4) Adjust the Cherry Pick Commit Message if needed
5) Click on Cherry Pick Change button
It'll be created a NEW CHANGE cherry-picked from the draft change. Go to the new change page and follow the regular Gerrit process (review, approve, submit). The original draft change can be abandoned or deleted.
We use Jenkins to verify patch sets. Sometimes Jenkins needs do some changes on the patch set. So it commit --amend the changes and then uploads the new patch set.
It work nicely besides the fact, that all manual reviews made to the original patch set get erased.
How can I push a new patch set (from Jenkins) without loosing all existing reviews/votes?
Be aware that, in the situation you have described, you have a new patchset and, excluding in special situations, you don't want votes of the old patchset copied forward to the new patchset. For example: if someone have approved the patchset1 and Jenkins pushes the patchset2, probably he/she doesn't want to have his/her vote automatically copied to patchset2.
Said that: you can control how votes will/won't be copied forward to new patchset setting the label.LABEL-NAME.copyXXXXX options of the project. See more info in Gerrit documentation here.
Why is the default gerrit change-id commit-hook not a pre-push-hook?
The default Change-Id "commit-msg"-hook in gerrit adds a Change-Id to every commit. Why is in not implemented as a "pre-push"-hook? If it where it could add Change-Ids only to commits that are pushed to refs/for/...
With the current setup I get Change-Ids in commits that I want to push directly (without a review). It's ugly.
I think I know the answer now.
It would be bad practice for a pre-push hook to change the contents that is being pushed. It could block a push from happening but changing the commits and then automatically precede with the push without the user having a chance to review the changes is bad practice.
I am Sajid, I like to know Is it possible that I can go back to my previous patch in my commit. I can explain:
I commit something. On the way to delivery, i fixed and update things and pushed into gerrit with commit --amend. But what I am experiencing now my last patch is a faulty so I like to go back to previous patch. and I don't know how can i point to my previous patch. And I also like to know will it be the same procedure even If I go to any previous patch.
thanks in advance.
As this answer said, patchsets can not be reverted. so first you have to checkout one of the previous patchset. you can get the command from Gerrit review board at each patchset download panel. For example:
git fetch https://android.googlesource.com/kernel/tegra refs/changes/43/69243/2 && git checkout FETCH_HEAD
After checking it out amend it to generate new commit hash then pushed again as a new patchset.