Can you "ignore" a directory in P4V?

Updated answer: This has been somewhat tricky in the past, because there was no built-in way to exclude a directory from a Perforce command. Since 2012 this has changed. You can have a look at a nice perforce article for this problem.

As of 2012.1, the P4IGNORE environment variable can be set to designate a file to be used to exclude files from Perforce. Both the Perforce Server (p4d) and client (p4, P4V) need to be 2012.1 or greater. P4IGNORE's purpose is to ignore files when adding new files to the depot and reconciling workspaces. Like comparable features in other version control systems, P4IGNORE cannot be used to ignore files already under the repository's control.

P4Eclipse manages .p4ignore files on its own terms. (see the manual regarding this point here)

Using client views to exclude files and directories:

The traditional method for excluding files and directories in Perforce is to use exclusionary client mappings. See the command reference for Views for full documentation. Example view:

View:

//depot/... //test_ws/depot/...
-//depot/dir/etc/... //test_ws/depot/dir/etc/...

This view will prevent files in dir/etc from being added to the depot. If trying to exclude the directory from read-only queries, use client or relative syntax.

$ p4 files //depot/dir/etc/...
//depot/dir/etc/foo#1 - add change 1186 (text)
//depot/dir/etc/bar#1 - add change 1186 (text) 


$ p4 files //test_ws/dir/etc/...
//test_ws/test_ignore/ignoredir/... - file(s) not in client view. 

$ cd dir/etc
$ p4 files ...
... - file(s) not in client view.

Alternatively, you can use shell commands to filter your output as desired.

p4 files //depot/dir/... |
    awk -F# '{print $1}' |
    grep -v "//depot/dir/etc/" |
    p4 -x - fstat

which runs p4 fstat on all files under "//depot/dir/", except for those files under "//depot/dir/etc/". This directory exclusion is accomplished by listing all of the files, and then using grep to remove those files under the directory to be excluded. The trailing slash in "//depot/dir/etc/" is necessary to prevent matching directories under "//depot/dir/" that start with "etc" (for example, "//depot/dir/etc2009").

Note:

The awk command assumes there are no file names containing the "#" character. The grep command can also read its patterns from a file, which is useful if you need to exclude multiple directories. We use the '-x -' flags with the p4 command to use the input as arguments to the corresponding command; see the Perforce Command Line Global Options for more information.


There is a way to do it directly in Perforce:

  • Connection menu
  • Edit Current Workspace...

Navigate the project tree. Right-click on the file or folder. Choose to include or exclude the file, the folder, the entire tree.


As of version 2012.1, Perforce supports the P4IGNORE environment variable. This allows you to specify files and directories to ignore when using the commands that search for or add new files (p4 add, p4 status, and p4 reconcile).

To use an ignore file, create a file in the root of your workspace and give it some meaningful name. The convention seems to be something like .ignore or .p4ignore, but anything will do (I used p4ignore.txt so that I can edit it with a simple double-click). Then fill it with your ignore rules. The following will ignore the the unwanted debris generated by Visual Studio:

# directories
bin
obj

# files
*.suo
*.user

After you have created this file, set the P4IGNORE environment variable to point to it. At the command line, type something along the lines of this:

p4 set P4IGNORE=C:\somepath\p4ignore.txt

Be sure to use an absolute path! The Perforce documentation doesn't specify this and my first attempt did not work (on Windows anyway) because I didn't specify an absolute path.

After doing this, any attempt to add files or directories that are in the ignore list will be rejected and you'll see a warning such as this (which they do give you the option to suppress):

P4V 'ignored' files message


If you are using a version of the Perforce server previous to 2012.1, you can still do this in your client spec. The syntax of your exclusion rules is just a little off. What you want is this:

-//depot/Foo.../*.user //Client/Foo.../*.user
-//depot/Foo...bin/... //Client/Foo...bin/...
-//depot/Foo...obj/... //Client/Foo...obj/...

Note the missing slashes after "Foo" and before "bin" and "obj".

Tags:

Perforce