Deleting Abandoned Commits from Gerrit Code Review

Back to Listing

Hanover, MD, 19 October 2013


And, we’re back!

So, it’s been an exciting time since my last post, the Government shut down, Gears of War overtook us on the Google front page, and the Government started back up until February.

Unfortunately, I hate to say that our actual HQ isn’t as awesome as this.

And now for something completely different. . .

diffymute-300x279For those of you that haven’t used the Gerrit Code Review system, I would highly recommend taking a look at it. Though it has its quirks, it has proven to be a stable and effective system for performing code reviews and has a growing community of users and developers dedicated to providing a robust product and ecosystem.

The one main issue that I have with Gerrit is described in issue #874. You simply can’t easily completely delete abandoned patchsets from the Gerrit GUI. Nor are there simple instructions on how to do so otherwise. This becomes a major issue if, like the issue states, you are storing large objects in your Gerrit repository or, frankly, someone shoved something awful in there that you simply need to erase forever.

How to Permanently Erase an Abandoned Commit from Gerrit

Now, be extremely certain that you want to delete this commit before you attempt this operation! You’re going to be editing the database directly so you don’t have the safety net that the web UI generally provides.

Set Up Your Gerrit Command Line Connection

If you haven’t yet gotten familiar with the Gerrit CLI utilities, now is the time. You’re going to need the gsql,flush-caches, and review commands to complete this exercise.

For the remainder of this document, we will have the command gerrit aliased to ‘ssh -p 29418 gerrit.domain gerrit‘.

Identify The Hash of the Change that you Wish to Delete

The simplest way to do this is to go to the Abandoned page in the web UI. The shortcut key sequence is ‘ga‘.

Once there, you need to find the tracking ID that Gerrit uses internally. If you click on the change set, the last number in the change page URL will be the number that you need.

For example: https://gerrit.domain/#/c/3

That ‘3’ on the end is the number of the change that you wish to delete.

Also, take note of how many patch sets you have with this commit. You’ll be deleting each one individually.

Change the Status of the Change Set to Draft

Open the GSQL interface

$ gerrit gsql
gerrit>

The following command will mark the change set as a draft change set in the Gerrit database.

gerrit> update changes set status='d' where change_id='3';

Next, update the associated patch sets.

gerrit> update patch_sets set draft='Y' where change_id='3';
gerrit> \q

Prior to making further changes, you need to make sure that the Gerrit caches have been flushed. If you don’t do this, you may end up with strange results when using the Web UI in relation to this change set.

$ gerrit flush-caches --cache changes

Finally, delete the patch set(s) that you had previously abandoned. In this case, we’re going to assume that you have two patch sets to delete.

$ gerrit review 3,1 --delete
$ gerrit review 3,2 --delete

Conclusion

If you now attempt to go to the change set URL that you had visited previously, you will find that the page is not available. Though it can be tedious for changes with a large number of patch sets, using the gerrit review command ensures that the database consistency is properly maintained over time.

Trevor has worked in a variety of IT fields over the last decade, including systems engineering, operating system automation, security engineering, and various levels of development.

At OP his responsibilities include maintaining overall technical oversight for Onyx Point solutions, providing technical leadership and mentorship to the DevOps teams. He is also responsible for leading OP’s solutions and intellectual property development efforts, setting the technical focus of the company, and managing OP products and related services. In this regard, he oversees product development and delivery as well as developing the strategic roadmap for OP’s product line.

At Onyx Point, our engineers focus on Security, System Administration, Automation, Dataflow, and DevOps consulting for government and commercial clients. We offer professional services for Puppet, RedHat, SIMP, NiFi, GitLab, and the other solutions in place that keep your systems running securely and efficiently. We offer Open Source Software support and Engineering and Consulting services through GSA IT Schedule 70. As Open Source contributors and advocates, we encourage the use of FOSS products in Government as part of an overarching IT Efficiencies plan to reduce ongoing IT expenditures attributed to software licensing. Our support and contributions to Open Source, are just one of our many guiding principles

  • Customer First.
  • Security in All We Do.
  • Pursue Innovation with Integrity.
  • Communicate Openly and Respectfully.
  • Offer Your Talents, and Appreciate the Talents of Others

gerrit, git

Share this story

We work with these Technologies + Partners

puppet
gitlab
simp
beaker
redhat
AFCEA
GitHub
FOSSFeb