你能“忽略”吗? P4V 中的目录?

发布于 2024-09-06 20:14:47 字数 603 浏览 7 评论 0原文

我们使用 Visual Studio,它会生成大量 binobj 目录。当我使用P4V的“协调离线工作”功能时,这些文件出现在“不在库中的本地文件”列表中。

我想排除他们。我发现这个问题,但那谈论的是文件,当我尝试它的建议(将以下内容添加到我的工作区视图中),它不起作用

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

它实际上似乎不适用于文件:仍然显示 foo.csproj.user 文件在列表中。

我可以从 P4V 中排除目录吗?如果是这样,怎么办?我做错了什么?

We use Visual Studio, which generates lots of bin and obj directories. When I use P4V's "Reconcile Offline Work" feature, these appear in the "Local files not in depot" list.

I'd like to exclude them. I found this question, but that talks about files, and when I try what it suggests (adding the following to my workspace view), it doesn't work:

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

It doesn't actually seem to work for files, either: the foo.csproj.user files are still displayed in the list.

Can I exclude directories from P4V? If so, how? What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

如梦 2024-09-13 20:14:47

从版本 2012.1 开始,Perforce 支持 P4IGNORE 环境变量。这允许您在使用搜索或添加新文件的命令(p4 addp4 statusp4 reconcile 时指定要忽略的文件和目录。代码>)。

要使用忽略文件,请在工作区的根目录中创建一个文件并为其指定一些有意义的名称。约定似乎类似于 .ignore.p4ignore,但任何内容都可以(我使用 p4ignore.txt 这样我就可以编辑它只需双击即可)。然后用您的忽略规则填充它。以下内容将忽略 Visual Studio 生成的不需要的碎片:

# directories
bin
obj

# files
*.suo
*.user

创建此文件后,将 P4IGNORE 环境变量设置为指向它。在命令行中,键入以下内容:

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

请务必使用绝对路径! Perforce 文档 没有指定这一点,我的第一次尝试没有成功(无论如何在 Windows 上),因为我没有指定绝对路径。

执行此操作后,任何添加忽略列表中的文件或目录的尝试都将被拒绝,并且您将看到如下警告(它们确实为您提供了抑制的选项):

P4V 'ignored' files message


如果您使用的是 2012.1 之前的 Perforce 服务器版本,您仍然可以在客户端规范中执行此操作。您的排除规则的语法有点不对劲。你想要的是这样的:

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

注意“Foo”之后和“bin”和“obj”之前缺少的斜杠。

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".

愿与i 2024-09-13 20:14:47

更新的答案
这在过去有些棘手,因为没有内置方法可以从 Perforce 命令中排除目录。自2012年以来,情况发生了变化。
您可以查看有关此问题的一篇不错的 perforce 文章

从 2012.1 开始,可以设置 P4IGNORE 环境变量来指定用于从 Perforce 中排除文件的文件。 Perforce Server (p4d) 和客户端(p4、P4V)都需要是 2012.1 或更高版本。 P4IGNORE 的目的是在将新文​​件添加到软件仓库并协调工作空间时忽略文件。与其他版本控制系统中的类似功能一样,P4IGNORE 不能用于忽略已在存储库控制下的文件。

P4Eclipse 按照自己的方式管理.p4ignore 文件。
(请参阅关于这一点的手册此处 )

使用客户端视图排除文件和目录:

在 Perforce 中排除文件和目录的传统方法是使用排除客户端映射。有关完整文档,请参阅视图的命令参考。示例视图:

视图:

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

此视图将阻止 dir/etc 中的文件添加到软件仓库中。如果尝试从只读查询中排除目录,请使用客户端或相对语法。

$ 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.

或者,您可以使用 shell 命令根据需要过滤输出。

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

它对“//depot/dir/”下的所有文件运行 p4 fstat,“//depot/dir/etc/”下的文件除外。此目录排除是通过列出所有文件,然后使用 grep 删除要排除的目录下的那些文件来完成的。 “//depot/dir/etc/”中的尾部斜杠是必要的,以防止匹配“//depot/dir/”下以“etc”开头的目录(例如,“//depot/dir/etc2009”)。

注意:

awk 命令假定不存在包含“#”字符的文件名。
grep 命令还可以从文件中读取其模式,如果您需要排除多个目录,这非常有用。
我们在 p4 命令中使用“-x -”标志,将输入用作相应命令的参数;有关详细信息,请参阅 Perforce 命令行全局选项。

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.

離人涙 2024-09-13 20:14:47

有一种方法可以直接在 Perforce 中执行此操作:

  • “连接”菜单
  • “编辑当前工作空间...”

导航项目树。
右键单击文件或文件夹。
选择包含或排除文件、文件夹、整个树。

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.

咽泪装欢 2024-09-13 20:14:47

这对我来说非常有用:

//depot/... //my_workspace_name/...
-//depot/.../.git/... //my_workspace_name/.../.git/...
-//depot/.../xcuserdata/... //my_workspace_name/.../xcuserdata/...
-//depot/.../xcschemes/... //my_workspace_name/.../xcschemes/...
-//depot/.../xcdebugger/... //my_workspace_name/.../xcdebugger/...

This works great for me:

//depot/... //my_workspace_name/...
-//depot/.../.git/... //my_workspace_name/.../.git/...
-//depot/.../xcuserdata/... //my_workspace_name/.../xcuserdata/...
-//depot/.../xcschemes/... //my_workspace_name/.../xcschemes/...
-//depot/.../xcdebugger/... //my_workspace_name/.../xcdebugger/...
哆兒滾 2024-09-13 20:14:47

这可能不相关,但如果任何路径中有空格,您需要确保已将它们正确括在“”中,但不要将 - 括在引号内。

This may not be relevant, but if there are spaces in any of your paths you need to ensure you have correctly enclosed them in "" but dont enclose the - inside the quotes.

っ〆星空下的拥抱 2024-09-13 20:14:47

当我添加要忽略的文件夹时,它们没有被应用,因为我指定了文件夹的路径,这是一个错误,您只需指定要忽略的文件夹的名称。

When I added the folders to ignore, they were not applied because I specified the path to the folders, and it was a mistake, you just need to specify the name of the folder that you want to ignore.

七秒鱼° 2024-09-13 20:14:47

该方法不适用于本地软件仓库,但如果您有流软件仓库,则可以创建虚拟流并以集中方式为所有开发人员排除二进制文件文件夹。

虚拟流的高级路径设置可能是这样的:

share ...
exclude bin/...
exclude logs/...

https: //www.perforce.com/manuals/p4v/Content/P4V/streams.virtual.html

Method won't work with local depot, but if you have a stream depot, you can create a virtual stream and exclude your binaries folders in centralized way for all developers.

Advanced path settings of virtual stream could be something like that:

share ...
exclude bin/...
exclude logs/...

https://www.perforce.com/manuals/p4v/Content/P4V/streams.virtual.html

雪落纷纷 2024-09-13 20:14:47

我将继续协调离线工作并完成除提交之外的所有操作。在提交之前,执行以下操作:

p4 revert //Client/Foo/.../*.user

p4 revert //Client/Foo/.../bin/...

p4 revert //Client/Foo/.. ./obj/...

它不是自动化的,但这是我目前能想到的最好的。

I would go ahead with the Reconcile Offline Work and do everything but the submit. Before the submit, do the following:

p4 revert //Client/Foo/.../*.user

p4 revert //Client/Foo/.../bin/...

p4 revert //Client/Foo/.../obj/...

It's not automated, but that's the best I can think of at the moment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文