Can you "ignore" a file in Perforce?
Asked Answered
L

11

104

I sometimes use the feature 'Reconcile Offline Work...' found in Perforce's P4V IDE to sync up any files that I have been working on while disconnected from the P4 depot. It launches another window that performs a 'Folder Diff'.

I have files I never want to check in to source control (like ones found in bin folder such as DLLs, code generated output, etc.) Is there a way to filter those files/folders out from appearing as "new" that might be added. They tend to clutter up the list of files that I am actually interested in. Does P4 have the equivalent of Subversion's 'ignore file' feature?

Lase answered 10/9, 2008 at 22:45 Comment(3)
Could you provide an example of the CVS output so we can see what you mean, and why the answers given don't do what you want?Dupion
At Perforce's idea's forum, you can vote on a suggestion for Git-style ignore lists p4ideax.com/ideas/15/ignore-supportRyter
Hit "Reconcile Offline Work", untick "Local files not in depot", push "Reconcile". As long as you're not adding files then it's probably the quickest workaround.Mouthwatering
C
60

As of version 2012.1, Perforce supports the P4IGNORE environment variable. I updated my answer to this question about ignoring directories with an explanation of how it works. Then I noticed this answer, which is now superfluous I guess.


Assuming you have a client named "CLIENT", a directory named "foo" (located at your project root), and you wish to ignore all .dll files in that directory tree, you can add the following lines to your workspace view to accomplish this:

-//depot/foo/*.dll //CLIENT/foo/*.dll
-//depot/foo/.../*.dll //CLIENT/foo/.../*.dll

The first line removes them from the directory "foo" and the second line removes them from all sub directories. Now, when you 'Reconcile Offline Work...', all the .dll files will be moved into "Excluded Files" folders at the bottom of the folder diff display. They will be out of your way, but can still view and manipulate them if you really need to.

You can also do it another way, which will reduce your "Excluded Files" folder to just one, but you won't be able to manipulate any of the files it contains because the path will be corrupt (but if you just want them out of your way, it doesn't matter).

-//depot/foo.../*.dll //CLIENT/foo.../*.dll
Carraway answered 10/9, 2008 at 23:48 Comment(8)
While this works, it's not very useful as you will have to put these lines in to every workspace you ever create.Izettaizhevsk
Note: this does not work for the normal reconcile offline work from p4v. The "excluded files" only seem to be in the "advanced" reconcile window...Superlative
The exclude filter does not work inside the Reconcile Offline Work dialog. It does work if you open it inside Advanced Reconcile... but this is useless because in 99.9% of the the time you do not need or want to use the advanced dialog.Proximate
Imagine how easy is to do a reconcile on a Python project where the listing will contain hundreds of .pyc files. Also the idea of keeping the ignore rules on the workspace is a very poor one, who will imagine that all developers will be able to sync their ignore rules?Proximate
I didn't think you could get any more unnecessarily complex than the effort of copying a group of source file to a new location while preserving their change history. Then I tried to ignore files...Ellswerth
@raven: 1) (Example:) Some projects use bin/obj folders under each project instead of having them in a central location. (Generalized conclusion:) Perforce's assumption that all intermediate files are placed in an easily excluded workspace location is an unnecessarily restrictive design for a VCS to be making. 2) Some projects involve local cache and/or other per-user generated files in the directory structure (as an example, the *.ncb IntelliSense cache). The inability to exclude them as a common policy severely impairs the Reconcile Offline Work and Diff Folders features.Ellswerth
This particular problem is killing me.Bore
@raven: Want to exclude both (many) unit tests built as local .exe files, and their output which is redirected to out.txt files, without excluding tools built as .exe files or surprising authors of other content in the repository by excluding their files that happen to match a name pattern. I want settings with local effect.Boley
R
55

Yes, But.

Perforce version 2012.1 added a feature known as p4ignore, inspired by Git. However the Perforce developers made a change to the behaviour, without justification, that happens to make the feature a lot less useful.

Whilst Git takes rules from all .gitignore files, Perforce doesn't know where to look until you specify a filename in an environment variable P4IGNORE. This freedom is a curse. You can't hack on two repositories that use different names for their ignore files.

Also, Perforce's ignore feature doesn't work out the box. You can set it up easily enough for yourself, but others don't benefit unless they explicitly opt-in. A contributor who hasn't may accidentally commit unwelcome files (eg. a bin folder created by a build script).

Git's ignore feature is great because it works out the box. If the .gitignore files are added to the repository (everyone does this), they'll work out the box for everyone. No-one will accidentally publish their private key.

Amusingly, the Perforce docs shows '.p4ignore' as an example ignore rule, which is backwards! If the rules are useful, they should be shared as part of the repository.


Perforce could still make good on the feature. Choose a convention for the file names, say p4ignore.txt, so the feature works out the box. Drop the P4IGNORE environment variable, it's counterproductive. Edit the docs, to encourage developers to share useful rules. Let users write personal rules in a file in their home folder, as Git does.

If you know anyone at Perforce, please email them this post.

Ryter answered 10/9, 2008 at 22:45 Comment(4)
Thanks for clarification. I tried using .p4ignore with P4VS but my solution which was supposed to be ignored was not ignored. First I thought I was doing something wrong. Now I know better.Granthem
@gentlesea, as of Perforce 2013.1, the ignore feature finally works in the graphical app.Ryter
For configuration variables that differ based on which workspace you're using, try using P4CONFIG files. Then you can have your P4CONFIG file specify a different P4IGNORE value as you move around from workspace to workspace.Shoreline
Perforce doesn't know how to build proper software, they don't get even basics. That's why everyone who's stuck with perforce dreams about moving to git.Claudianus
K
22

This works as of Perforce 2013.1, the new P4IGNORE mechanism was first added in release, 2012.1, described on the Perforce blog here:

https://www.perforce.com/blog/new-20121-p4ignore

As it's currently described, you set an environment variable "P4IGNORE" to a filename which contains a list of the files to ignore.

So you can check it out to see how you like it.

Kiesha answered 15/2, 2012 at 0:41 Comment(3)
You can also include directory names, not just filenames.Jeromyjerreed
As mentioned previously: unfortunately, you HAVE to set P4IGNORE.Boley
I fixed the link @DerMike - I guess Perforce changed their blog URLs.Kiesha
Y
7

If you want a solution that will apply to all work-spaces without needing to be copied around, you (or your sysadmin) can refuse submission of those file-types through using lines like the below in the p4 protect table:

write user * * -//.../*.suo
write user * * -//.../*.obj
write user * * -//.../*.ccscc

I remember doing this before, but I don't have the necessary permissions to test this here. Check out Perforce's Sysadmin guide and try it out

Yiyid answered 11/6, 2010 at 8:3 Comment(1)
Unfortunately this causes errors on submit rather than having the reconcile view ignore. So it can keep certain files out of a repository, but it can't help your users not to see noise.Bore
D
6

Perforce Streams makes ignoring files much easier, as of version 2011.1. According to the documentation, you can ignore certain extensions or certain paths in your directory.

From p4 help stream

Ignored: Optional; a list of file or directory names to be ignored in
                 client views. For example:

                     /tmp      # ignores files named 'tmp'
                     /tmp/...  # ignores dirs named 'tmp'
                     .tmp      # ignores file names ending in '.tmp'

                 Lines in the Ignored field may appear in any order.  Ignored
                 names are inherited by child stream client views.

This essentially does what @raven's answer specifies, but is done easier with streams, as it automatically propagates to every work-space using that stream. It also applies to any streams inheriting from the stream in which you specify the ignore types.

You can edit the stream via p4 stream //stream_depot/stream_name or right-clicking the stream in p4v's stream view.

And as @svec noted, the ability to specify ignore files per workspace is coming soon, and is in fact in P4 2012.1 beta.

Diehard answered 2/3, 2012 at 18:10 Comment(2)
Yes, this works for me to share "ignore" settings across a team (I'm using p4 2013.2). Note that it only works in a streams-enabled depot. (If you can propagate the P4IGNORE=.p4ignore environment variable across your team that's probably the best solution.)Scutellation
Note that the Ignored field for a stream can be used to ignore a specific folder, file, or file extension, but wildcard support is limited and there is no way to ignore a whole folder and then "unignore" specific files or sub-folders. (As of p4 server version 2013.2)Scutellation
D
3

Will's suggestion of using .p4ignore only seems to work with the WebSphere Studio (P4WSAD) plugin. I just tried it on my local windows box and any files and directories that I listed were not ignored.

Raven's suggestion of modifying your client spec is the correct way under Perforce. Proper organization of your code/data/executables and generated output files will make the process of excluding files from being checked in much easier.

As a more draconian approach, you can always write a submit trigger which will reject submission of change-lists if they contain a certain file or files with a certain extension, etc.

Diverticulum answered 11/9, 2008 at 13:11 Comment(2)
I completely disagree with the whole "Proper organization of your code..." statement. The fact of the matter is, following Perforce's convention of editing the workspace requires every user to make the change. Whereas, a true .p4ignore file would only be created/managed once.Reduplication
Oh, and not to mention, you like to branch your code? Good luck maintaining your workspaces for each branch. That sounds like fun!Reduplication
B
2

HISTORICAL ANSWER - no longer correct. At the time this was written originally it was true;

You can not write and check in a file that the server will use to make ignore rules; general glob or regexp file pattern ignore in perforce.

Other answers have global server configurations that are global (and not per folder). The other answers show things that might work for you, if you want one line in your view per folder times number of extensions you want to ignore in that single folder, or that provide this capability in WebSphere Studio plugins only, or provide capability for server administrators, but not available to users.

In short, I find Perforce really weak in this area. While I appreciate that those who use the Eclipse Plugin can use .p4ignore, and I think that's great, it leaves those of us that don't, out in the dark.

UPDATE: See accepted answer for new P4IGNORE capability added mid-2012.

Bore answered 7/10, 2010 at 16:16 Comment(0)
E
1

I have found it easiest to reconcile offline work using a BASH script like this one:

#!/bin/bash
# reconcile P4 offline work, assuming P4CLIENT is set
if [ -z "$P4CLIENT" ] ; then echo "P4CLIENT is not set"; exit 1; fi
unset PWD # confuses P4 on Windows/CYGWIN

# delete filew that are no longer present
p4 diff -sd ... | p4 -x - delete

# checkout files that have been changed.  
# I don't run this step.  Instead I just checkout everything, 
# then revert unchanged files before committing.
p4 diff -se ... | pr -x - edit

# Add new files, ignoring subversion info, EMACS backups, log files
# Filter output to see only added files and real errors
find . -type f \
 | grep -v -E '(\.svn)|(/build.*/)|(/\.settings)|~|#|(\.log)' \
 | p4 -x - add \
 | grep -v -E '(currently opened for add)|(existing file)|(already opened for edit)'

I adapted this from this Perforce Knowledge Base article.

Embitter answered 11/2, 2011 at 19:10 Comment(2)
That was seven years ago, I'm not surprised. I'm surprised anyone is still using Perforce.Embitter
...not by choice :'(Rossiter
S
0

I'm looking for a .p4ignore like solution as well (and not one tied to a particular IDE). Thus far, the closest thing I've found is p4delta. It sounds like it will do exactly what the original poster was asking, albeit through another layer of indirection.

http://p4delta.sourceforge.net

Unfortunately, while this does seem to produce the proper list of files, I can't get "p4delta --execute" to work ("Can't modify a frozen string") and the project has not been updated in year. Perhaps others will have better luck.

Sarnoff answered 26/7, 2011 at 14:0 Comment(0)
M
0

(adapted from Bryan Pendleton's comment from Jul 18, 2013 at 13:54 )

One solution
  1. Create .p4ignore in the topmost directory of this client spec
  2. Add to a .p4config file the line P4IGNORE=.p4ignore in the topmost directory of this client spec
  3. Set env variable P4CONFIG to .p4config
    • export P4CONFIG=.p4config # sh

You can have your P4CONFIG file specify a different P4IGNORE value as you move around from workspace to workspace. – Bryan Pendleton Jul 18, 2013 at 13:54

Music answered 19/9, 2023 at 18:56 Comment(0)
O
-1

If you are using the Eclipse Perforce plugin, then the plugin documentation lists several ways to ignore files.

Onetoone answered 25/1, 2010 at 9:43 Comment(1)
duplicate, and doesn't answer the questionBore

© 2022 - 2025 — McMap. All rights reserved.