Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove untracked files from a Perforce working tree?

Tags:

perforce

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.

like image 623
Simon Perreault Avatar asked Aug 31 '09 13:08

Simon Perreault


People also ask

Which removes untracked files from your working directory?

You can use the git clean command to remove untracked files. The -fd command removes untracked directories and the git clean -fx command removes ignored and non-ignored files.

How do I permanently delete untracked files in git?

Run 'git clean -n' to see a dry run; Run 'git clean -f' to force untracked file deletion; Use 'git clean -f -d' to remove untracked directories; Use 'git clean -f -x' to remove untracked .

What does p4 clean do?

Description. The p4 clean command takes the following actions when finding inconsistencies between files in a user's workspace and corresponding depot files: Files present in the workspace, but missing from the depot are deleted from the workspace. Files present in the depot, but missing from your workspace.


2 Answers

Using P4V, you can right click on a folder and select "Reconcile Offline Work...". In the middle panel ("Local files not in depot"), all the files that Perforce can find in the folder tree that are not in the depot will be listed. You can select some or all of these and right click and select "Delete Local File"

This isn't a script, but it's much easier than most other solutions on Windows.

like image 145
scott77777 Avatar answered Sep 17 '22 17:09

scott77777


Try (for Unix) from your top-level:

# Find all files and filter for those that are unknown by Perforce find . -type f | p4 -x - fstat 2>&1 > /dev/null | sed 's/ -.*$//' > /tmp/list ### manually check /tmp/list for files you didn't mean to delete # Go ahead and remove the unwanted files. xargs rm < /tmp/list 

Or, for a clean -f kind of approach just pipe directly to xargs rm instead of first staging the file list in /tmp/list.

like image 22
Emil Sit Avatar answered Sep 20 '22 17:09

Emil Sit