Alex Rivera | Logout

How to remove untracked files from a Perforce working tree?

Asked 2009-08-31T13:28:17.683
33

What's the equivalent of "git clean" with Perforce?

git-clean - Remove untracked files from the working tree

Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.

-x Don’t use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore rules given with -e options. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git reset) to create a pristine working directory to test a clean build.

-X Remove only files ignored by Git. This may be useful to rebuild everything from scratch, but keep manually created files.

Edit
Report

1 Answer

4

There is no equivalent. Perforce has no command to remove files that are not under its control. You can see them in P4V, on the Workspace tab (they have plain white icons rather than the lined icons with the green dot) and delete them manually. If you want to automate the process, the easiest thing to do would be to remove the files from your workspace, delete everything in the directory, then sync it back up. A batch file to do it would look something like this:

p4 sync "//depot/someFolder/...#0"
erase C:\projects\someFolder\*.* /s /q /f
rd C:\projects\someFolder /s  /q
p4 sync -f "//depot/someFolder/..."

The first line is optional if you use the force switches on the erase and sync commands.


That solution has its drawbacks however. If you're currently working on any of the files, you obviously don't want to wipe them out. Also, a full sync can take quite a while if there is a huge amount of data in the directory tree you wish to clean.

A better way to do it would be to have your clean utility (I think we've grown beyond a batch file at this point) grab the list of files under version control using the p4 files command. Then iterate through all the files in the directory, deleting those that don't appear on the list.

answered 2009-08-31T21:32:26.640

Your Answer