所以我花了一些时间让它在 bash 的不同场景下工作,即使它不是特定于 dotnet 的,我想我会分享我的结果,因为这些概念是通用的。
您有两个选项可以从远程获取文件:
- 使用临时客户端/工作空间检查并同步工作空间映射,就像 Sam Stafford 在他的回答中所写的那样。这是 bash 中的注释:
# p4 uses this global variable as client/workspace name by default.
# Alternatively, you can also use -c in every command.
P4CLIENT="TEMP_SCRIPT_CLIENT"
# mapping remote folder to relative workspace folder (recursive)
wokspaceMapping="//depot/dir1/... //$P4CLIENT/..."
p4 client -d $P4CLIENT # make sure the workspace does not exist already
# Creating a client on the console gives an editor popup to confirm the
# workspace specification, unless you provide a specification on stdin.
# You can however generate one to stdout, and pipe the result to stdin again.
p4 --field View="$wokspaceMapping" --field Root="/some/local/path" client -o |
p4 client -i
p4 sync -p # download all the files
p4 client -d $P4CLIENT # remove workspace when you are done.
- 用于打印jhwist 所
p4 print
建议的每个文件的内容,因此您根本不需要定义工作区。缺点是您必须单独处理每个文件,并自己创建任何目录。
p4RemoteRoot="//depot/dir1"
# First, list files and strip output to file path
# because `p4 files` prints something like this:
# //depot/dir1/file1.txt#1 - add change 43444817 (text)
# //depot/dir1/folder/file2.txt#11 - edit change 43783713 (text)
files="$(p4 files $p4RemoteRoot/... | sed 's/\(.*\)#.*/\1/')"
for wsFile in $files; do
# construct the local path from the remote one
targetFile="$localPath/${wsFile#$p4RemoteRoot/}"
# create the parent dir if it doesn't exist. p4 files doesn't list directories
mkdir -p $(dirname $targetFile)
# print the file content from remote and write that to the local file.
p4 print -q $wsFile > $targetFile
done
注意:我找不到该--field
参数的任何文档,但您似乎可以使用文档中指定的“表单字段”中的所有内容:https ://www.perforce.com/manuals/v18.2/cmdref/Content /CmdRef/p4_client.html