[P4]Perforce (p4) Command Line: Tips and Tricks

本文介绍了如何使用Perforce命令行进行快捷操作,包括创建新 changelist、批量文件添加、分割大任务、打印文件和版本差异等。从创建20个changelist到高级的diff和changelist管理,适合Perforce初学者和经验者参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Perforce (p4) Command Line: Tips and Tricks

目录

Perforce (p4) Command Line: Tips and Tricks

Quick start with p4

Create a new change list

Create 20 new change lists

Add, checkout (edit), delete and revert

Add a bunch of files into a change list

Split a big changelist into little ones

Print files

The latest revision of a file

Diff between two revisions


Quick start with p4

  1. Open p4v (visual Perforce client).
  2. Right click on the project folder.
  3. Click "Open Terminal".
  4. Now you can use p4 in a preconfigured console, you don't need to setup workspace and server connection.

Create a new change list

p4 change -o | p4 change -i
  • p4 change -o: default change list description
  • p4 change -i: create new change list

Create 20 new change lists

for i in {1..20}; do
  p4 change -o | p4 change -i;
done

Add, checkout (edit), delete and revert

  • Default change list:
    p4 add ./file
    p4 edit ./file
    p4 delete ./file
    p4 revert ./file
    
  • Custom change list:
    p4 add -c 12345678 ./file
    p4 edit -c 12345678 ./file
    p4 delete -c 12345678 ./file
    p4 revert -c 12345678 ./file
    

Add a bunch of files into a change list

Imagine situation, when you need to add 40000 files into a single changelist to create an initial commit.

cat ./files | p4 -x- add -c 12345678
  • -x is an option where to read the input, and -x- means to read the files from standard input.
  • -c is an option of add operation to specify a concrete change list number.

Split a big changelist into little ones

Now, perhaps, you need to create a 40 changelists with 1000 files in the each one. And perhaps you have a file "files" with 40000 lines inside one. Then:

split -l 1000 ./files

Output is "xaa", "xab", "xac" files, total count is 40 new files per 1000 lines.

Create 40 change lists:

for i in {1..40}; do
  p4 change -o | p4 change -i;
done

Write down change list numbers. For example, we've got numbers 9901, 9902, and so on, up to 9940.

Rename files into existing change list numbers:

mv xaa 9901
mv xab 9902
mv xac 9903
# ...
mv xbp 9940

Add files according to change lists:

for i in 99*; do
  cat {i} | p4 -x- add -c {i};
done

File list "9901" will be added to the 9901 change list
File list "9902" will be added to the 9902 change list.
And so on.

Print files

  1. In the local folder of workspace:
    p4 files "*"
    
  2. In the local folder recursively:
    p4 files "..."
    
  3. In the remote depot:
    p4 files "//Depot/..."
    

The latest revision of a file

p4 filelog -m1 ./file

Diff between two revisions

p4 diff2 -u file#3 file#5
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

元直数字电路验证

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值