Exclude Files from P4 Server Control

Your workspace might include files that you do not want to add to the P4 Server repository, such as files used or generated by automated build processes.

 

You can use Visual Studio to exclude a file from a solution by right-clicking the file in Solution Explorer and selecting Exclude from Project in the context menu. If the file is under P4 Server control, P4 for Visual Studio prompts you to mark the file for delete, and after submitting the changelist that includes the deletions, the file is removed from both the project and the P4 Server repository.

You can also use Ignore Lists in P4 for Visual Studio to specify files or filetypes that you want to keep in your project but do not want to add to the P4 Server repository. An Ignore List is a file in your local workspace directory that contains a list of file names or file types to ignore, each on a separate line.

For example, you can create an Ignore List called .p4ignore in your project folder that contains the following:

*.swp
*~
tmp/*
.p4ignore.txt

Optionally, the Ignore List file can be included in the list.

We recommend the following be included in your Ignore List:
Saved/
Intermediate/
DerivedDataCache/
*.pdb
obj/
*.vcxproj
*.sln
-Debug.
FileOpenOrder/
.vs/

You can add an Ignore List file at any level of the solution hierarchy in your workspace. If you set your P4IGNORE environment variable to the file name of the Ignore List file, P4 for Visual Studio will not mark the listed files and filetypes for add, nor will it prompt you to do so.

Ignore Lists only affect commands that search for and add new files. If you have already marked a file for add, P4 for Visual Studio will not ignore it, even if it or its filetype appear in an Ignore List.

You can add Ignore Lists at any folder level in your workspace (or solution). P4 for Visual Studio applies the rules in the Ignore List at the deepest folder level relative to the file being checked, along with the rules in any Ignore Lists found in parent folders (although you can use the ! character to override higher-level rules.)

The syntax for ignore rules is not the same as P4 Server syntax. Instead, it is similar to that used by other versioning systems:

  • Files are specified in local syntax
  • # at the beginning of a line denotes a comment
  • ! at the beginning of a line excludes the file specification
  • * wildcard matches substrings

For example:

foo.txt

Ignore files called foo.txt

*.exe

Ignore all executables

!bar.exe

Exclude bar.exe from being ignored

While you can set your local P4IGNORE environment variable and add Ignore Lists manually, P4 for Visual Studio provides preferences and context menu options to simplify the process of adding and editing Ignore Lists.

Set Ignore List preferences

Go to Tools > Options > Source Control > P4 - Ignoring Files to set Ignore List preferences, including the Ignore List file name. The file name you enter in your preferences is set by P4 for Visual Studio as the local P4IGNORE environment variable and used for all of your Ignore Lists. To learn more about setting Ignore List preferences, see Set P4 for Visual Studio preferences.

Add a file to an Ignore List

To add a file to an Ignore List in Solution Explorer, right-click the file and select Manage Files > Add to Ignore List. P4 for Visual Studio adds the file to the Ignore List in the current folder. If there is no Ignore List file in the current folder, P4 for Visual Studio creates one. P4 for Visual Studio denotes an ignored file with a gray circle glyph next to the file icon.

Remove a file from an Ignore List

To remove a file from an Ignore List in Solution Explorer, right-click the file and select Manage Files > Remove from Ignore List. P4 for Visual Studio adds an exclusionary (!) line for the file in the Ignore List in the current folder, which overrides any Ignore Lists in parent folders.

Edit Ignore Lists

To edit an Ignore List in Solution Explorer, right-click any file in the same folder and select Manage Files > Edit Ignore List. P4 for Visual Studio opens the Ignore List file for edit. If there is no Ignore List file in the current folder, P4 for Visual Studio creates one. Use Edit Ignore List when you want to add file types using wildcard expressions.