P4IGNORE

Specify a filename or list of filenames that contain rules for ignoring files when adding client workspace files to the depot (p4 add) and when reconciling client workspaces (p4 reconcile).

Usage Notes

Each client machine can have its own rules, which apply to how the client interacts with the Helix Core Server.

Used by Client? Used by Server? Command-Line Alternative Can be set in P4CONFIG file?

Yes

No

None

Yes

To see the rules for your client machine, use the p4 ignores -v command.

Test your rules to ensure that they work as expected.

Default P4IGNORE files

Operating System File Names Note

All

.p4ignore

p4ignore.txt

The .p4ignore file, if present, is processed first, followed by p4ignore.txt file, if present.

The default file names do not appear in the output of p4 set because they are in place without setting P4IGNORE.

Prerequisites for the default file names

Prior to the 2023.2 release of Helix Core Server, no rule file name was set by default. The prerequisites for P4IGNORE automatically looking for the default file names are an installation of:

  • Helix Core Server 2023.2 (or later)

  • a compatible version of a Helix Core client, such as:

    • the p4 client included with the 2023.2 Server (or later), or

    • P4V 2023.4 (or later)

See also Default ignored paths in the p4 ignores topic.

Set a list of files containing rules

You can set a list of files with rules. This means that .p4ignore and p4ignore.txt do not apply by default, but can be explicitly set. For example,

p4 set P4IGNORE=.p4ignore;/etc/.systemp4ignore;$home/my-rules-for-ignore

Such a list:

  • Specifies rule files that are read in the order presented.

  • Uses semicolon (;) as the separator.

  • Can contain absolute and relative file paths.

Notes and examples

Within the file that specifies rules for ignore, each rule must be on its own separate line. For example,

# files to ignore
readme.txt
*.html
my-logo.png

Use the p4 ignores command to determine which line of the P4IGNORE file is being used to ignore a file:

p4 ignores -v -i my-path

The syntax for the contents of a P4IGNORE file is not the same as Helix Server syntax. Instead, it is similar to that used by other versioning systems. Consider the following.

Token Syntax Example Explanation
#
# Ignore the #example.html file
\#example.html
A # character at the beginning of a line denotes a comment. You can escape the # comment character with a backslash (\). This allows filenames beginning with # to be ignored.

.p4ignore

 

# Ignore my private .p4ignore files so p4 clean does not remove them
.p4ignore

 

Although P4IGNORE automatically includes the P4CONFIG and P4ROOT filenames, it does not automatically include the P4IGNORE filename. If you want to have a private P4IGNORE file that is not under source control, include your private P4IGNORE file in the P4IGNORE file list. Otherwise, p4 clean removes any private P4IGNORE files when it makes the workspace match the depot.Rules are specified using local filepath syntax. Unix style paths will work on Windows for cross-platform file support.

!
# Ignore all HTML files except the readme file
*.html
!readme.html 

 

A ! character at the beginning of a line excludes the file specification. These exclusions override rules defined above it in the P4IGNORE file, but can be overridden by later rules. This scenario applies where the P4IGNORE file exists in more than one directory, and one of those directories is a subdirectory of the other.

/
# Ignore the bin directory
bin/

A / (or \ on Windows) character at the end of a line causes the file specification to only match directories, and not files of the same name.

/
# Ignore the build.properties file in this directory
/build.properties

A / (or \ on Windows) character at the beginning of a line causes the file specification to be considered relative to the P4IGNORE file. This is useful when the rule must apply to files at particular depots of the directory tree.

*
# Ignore all object files, shared libraries, and executables
*.dll
*.so
*.exe
*.o
The * wildcard matches substrings. Like the Helix Server wildcard equivalent, it does not match path separators. However, if the * wildcard is not used as part of a path, the directory scanning nature of the rule may make it appear to perform like the Perforce "..." wildcard.
**
# Ignore all text files in test directories
test/**.txt
The ** wildcard matches substrings, including path separators. It is equivalent to the Helix Server "..." wildcard, which is not permitted.

Setting P4IGNORE with a relative path

You can set P4IGNORE with a relative path. For example,

p4 set P4IGNORE=.p4ignore

or

p4 set P4IGNORE=p4ignore.txt

If the name of the rule file is set with a relative path, a file with that name can be in a single directory location or multiple directories. A rule applies to the directory of the P4IGNORE file it is found in and its subdirectories.

A rule in a subdirectory can prevent files from being added at that level. For example, the top-level rule might prevent .html files from being added, and a rule in a subdirectory can supplement the rule it inherits with an additional rule to prevent .txt files from being added.

A subdirectory rule can can override a rule set in a parent directory. For example, if a rule in a subdirectory is

# allow the readme.html file to be added
! readme.html

it overrides at that level a more general rule in a parent directory that says:

# do not add HTML files
*.html

Setting P4IGNORE with an absolute path

To make P4IGNORE use exactly one file, set P4IGNORE to an absolute path. For example,

p4 set P4IGNORE=C:\users\maria\my-ignore-rules.txt

Linux and MacOS support using $home for setting environment variables. For example,

p4 set P4IGNORE=$home/my-ignore-rules

Windows supports using %USERPROFILE% for setting environment variables. For example,

p4 set P4IGNORE=%USERPROFILE%\my-ignore-rules.txt

which is interpreted as an absolute path to a directory such as C:\users\maria\my-ignore-rules.txt