May 1, 2014

p4 clean: Make Your Workspace Shine

Healthcare
angry customer
Image: PhylB via Flickr

The 2014.1 server release introduces a new command, 'p4 clean,' that at a single stroke makes your workspace consistent with the depot. Files that have been modified or deleted are restored and extra files are deleted, leaving you with a set of files that exactly matches what you'd have if you'd just done a fresh sync into an empty directory.

The new 'clean' command is part of the same family as 'reconcile' and 'status', and can also be invoked as 'reconcile -w'.  If you're already familiar with 'reconcile', you can simply imagine that 'clean' is what you'd get if you ran 'reconcile' and then immediately did 'revert -w' on all of the files that were opened—in other words 'clean' detects inconsistencies the same way that 'reconcile' does, but instead of opening the files (so that you can submit your changes to the depot) it refreshes them (so that your changes are discarded).

Here are a few potential uses for 'p4 clean':

  • Ensuring a clean build environment without a time-consuming "rm -rf; p4 sync -f".
  • Reconstituting a workspace—drop files in place, "p4 flush", "p4 clean" to take care of stragglers.
  • Got a bunch of temp files and build artifacts cluttering your workspace?  Not any more!

A few fine points of usage:

  • Your workspace is reset to the last explicitly synced revision (#have), not necessarily the latest revision (#head).
  • Files are only refreshed if they're detected as different (via checksum comparison, or modtime if the -m option is used).
  • Added files can be ignored via P4IGNORE, and P4IGNORE can be overridden with the -I flag.
  • 'p4 clean' requires a 2014.1 (or later) server.

Download 14.1 and start your spring cleaning today!