perforce 使用教程(zz)


http://www.perforce.com/documentation/perforce_technical_documentation

http://blog.csdn.net/brucexu1978/article/details/7181768

http://www.perforce.com/perforce/doc.current/manuals/cmdref/sync.html

P4遞交建議流程:

1. p4 sync

2. 覆蓋或者改動local文件

3. p4 delete or 直接delete 廢棄的文件

4. p4 add: 增加新文件到depot

5. p4 diff -se: 查看編輯過的文件

6. p4 diff -se | p4 -x - edit: 把所有改動過的文件置為open for submit,對於覆蓋的文件 or沒有用p4 edit的文件,需要這個命令, 才能將文件置為open狀態, 才能方便遞交

7. p4 diff -sd: 查看刪除的文件(未用p4 delete刪除的)

8. p4 diff -sd | p4 -x - delete: 置刪除的文件為opened狀態, 方便遞交

9. p4 submit -d 'xxx': 遞交

P4可以差分遞交, 只要別人的遞交沒有影響到你的遞交, 任何時候都可遞交, 這一點, 和svn相同, 和git不同。

恢復:

p4 revert -a (file 可選): revert所有打開的已經存在的文件

 

p4 revert //...

Revert every file you have open, in every one of your pending changelists, to its pre-opened state.

p4 revert -c default //...

Revert every file open in the default changelist to its pre-opened state.

p4 revert -n *.txt

Preview a reversion of all open .txt files in the current directory, but don't actually perform the revert.

p4 revert -c 31 *.txt

Revert all .txt files in the current directory that were open in changelist 31.

p4 revert -a

Revert all unchanged files. This command is often used before submitting a changelist.

p4 revert file: revrt 已經打開的已經存在的文件或者新add的文件

p4 sync -f: 強行同步到head changelist, 如果有打開的文件, 需要先revert

下面是網上的資料, 通用但不實用:

環境變量:
export P4PASSWD=abcdefg
export P4CLIENT=xxx //這個可以不設
export P4USER=yyy
export P4PORT=ip:port

1. p4 client #配置本地信息,文件下載在哪里在這里面配置,Root項

   -t clientname
拷貝客戶工作區 clientname 的視圖和客戶選項到該工作區的視圖和選項字段中去(i.e, 使用 clientname's 視圖作為一個模版)

   -d client name 刪除這個client



2、p4 sync #從perforce 下載文件

p4 sync
Copy the latest revision of all files from the depot to the client workspace, as mapped through the client view.
If the file is already open in the client workspace, or if the latest revision of the file exists in the client workspace, it is not copied.
p4 sync file.c#4
Copy the fourth revision of file.c to the client workspace, with the same exceptions as in the example above.
p4 sync //depot/proj1/...@21
Copy all the files under the //depot/proj1 directory from the depot to the client workspace, as mapped through the client view.
Don't copy the latest revision; use the revision of the file in the depot after changelist 21 was submitted.
p4 sync @ labelname
If labelname is a label created with p4 label, and populated with p4 labelsync, bring the workspace into sync with the files and revision levels specified in labelname.
Files listed in labelname, but not in the workspace view, are not copied into the workspace.
Files not listed in labelname are deleted from the workspace. (That is, @ labelname is assumed to apply to all revisions up to, and including, the revisions specified in labelname. This includes the nonexistent revision of the unlisted files.)
p4 sync @ labelname,@ labelname
Bring the workspace into sync with a label as with p4 sync @labelname, but preserve unlabeled files in the workspace.
(The revision range @ labelname ,@ labelname applies only to the revisions specified in the label name itself, and excludes the nonexistent revision of the unlisted files.)
p4 sync @2001/06/24
Bring the workspace into sync with the depot as of midnight, June 24, 2001. (That is, include all changes made during June 23.)
p4 sync status@june1st.txt
Sync a filename containing a Perforce wildcard by using the ASCII expression of the character's hexadecimal value. In this case, the file in the client workspace is status@june1st.txt.
p4 sync file.c#none
Sync to the nonexistent revision of file.c; the file is deleted from the workspace.
p4 sync ...#none
Sync to the nonexistent revision of all files; all files in the workspace (that are under Perforce control) are removed.

   p4 sync ...


3、p4 login #登陸perforce
4、p4 help #顯示關於命令的幫助
5、p4 -h #顯示關於p4的幫助
6、 p4 labels ... #顯示和這個目錄相關的標簽
7、p4 sync @label #同步標簽label中的所有文件
8、p4 files @label #查看標簽label所包含的文件列表
9、p4 revert #恢復所有打開的文件
10、p4 revert -n ... #恢復所有打開卻沒提交的文件
11、p4 branch brach #新建分支
12、p4 integrate -b brach #合並分支brach中描述的文件
13、p4 opened #查看打開的文件
14、p4 help commands #查看p4所有命令的幫助
15、4 dirs -H . #顯示當前目錄
16、p4 branches #顯示所有的分支
17、 p4 delete filename #從p4刪除文件
18、p4 changelists -L ... #顯示當前目錄下面所有文件的修改注釋
19、p4 label label #新建標簽 label,編輯標簽
20、p4 tag -l label ... #把當前目錄下面的所有文件添加到標簽 label
21、p4 changes ... #當前目錄的changelist

    如果想看某個changlist影響的文件,使用p4 describe changelist_number(changelist的number)

22: p4 reopen 如果已經創建了一個changelist,但是現在又打開了一個文件想加入到這個還沒有checkin的changelist中,使用這個命令。

  for example:

     p4 reopen -c changelist //...

-c changelist# file
Move all open files matching file pattern file to pending changelist changelist#. To move a file to the default changelist, use default as the changelist number
-c changelist# file
Move all open files matching file pattern file to pending changelist changelist#. To move a file to the default changelist, use default as the changelist number.
-t filetype file
When submitted, store file as type filetype. All subsequent revisions will be of that file type until the type is changed again.
See the File Types section for a list of file types.
See the Global Options section.
-c changelist# file
Move all open files matching file pattern file to pending changelist changelist#. To move a file to the default changelist, use default as the changelist number.
-t filetype file
When submitted, store file as type filetype. All subsequent revisions will be of that file type until the type is changed again.
See the File Types section for a list of file types.
See the Global Options section.

http://www.perforce.com/perforce/doc.current/manuals/cmdref/reopen.html

   

 查看workspace sync到的changelist

perforce的workspace其實是一些特定版本的文件的結合,相比只將workspace對應到某個特定的changelist,此方法更靈 活。changelist和文件間的關系為:每個changelist其實是某些特定版本文件的集合,但是並不是所有的版本的文件結合都對應到一個 changelist。perforce允許用戶將workspace同步到文件的某些特定版本,不一定對應一個chagnelist。

使用如下三步來確定workspace的最新狀態
p4 changes 命令可以查看workspace中文件集合所對應的最高chagnelist:
p4 changes -m1 //...#have
可以使用如下命令查看workspace中是否所有的文件都被sync到了最高changelist:
p4 sync -n @<changelist retuned by p4 changes>
如果以上命令顯示所有的文件都已經是updated,則表示workspace當前被sync到了最高changelist。
 

22、 p4 sync @10931 #sync file @changelist
23、 p4 sync ...@10929 #only sync localfile@changelist
24、p4 help revisions #查看關於文件范圍的幫助

export好變量之后,然后用1進行配置,就可以用p4 sync進行代碼下載了

如果commandbar是目錄則后面要加上/...,如果是文件的話就不用

在虛擬機上使用p4

一共分為如下幾步:

1. 要在 Linux 上用 P4 ,就需要虛擬機能夠訪問外網

2. 安裝及配置 P4

3. 配置源代碼環境

 

下面具體介紹一下各個步驟:(我稱我們的工作機本身為“主機”)

1. 配置虛擬機訪問外部網絡。設置步驟如下

1) 共享主機網卡

本地連接 -》 屬性 -》高級 -》選擇允許其它網絡通過本...,並選擇家庭網絡連接為 VMware Network Adapter VMnet1

 

2) 設置虛擬機 IP 信息

選擇 Traditional ….


3) 設置靜態 IP

IP 192.168.0. xxx

Subnet mask 255.255.255.0

DNS 192.168.0.1(編輯/etc/reslove.conf)

Default Gateway 192.168.0.1

2. 安裝及配置 P4

1) 下載客戶端 http://www.perforce.com/perforce/downloads/index.html 我使用的是 The Perforce Command-Line Client (P4)

2) 把客戶端放在文件夾 /usr/local/bin 。這樣能在任何目錄直接使用 p4 命令

3) 配置客戶端,在線幫助有很多種方式,我使用配置文件方式。步驟如下

a. 在 /usr 下面新建一個文件夾 p4config ( 可以自定義 ) ,在文件夾里面新建文件 p4.configfile.

b. 用 VI 打卡 p4.configfile, 輸入如下配置

 

P4CLIENT= (定義你的工作空間,比如 ygxu_xms )

P4PASSWD= (你的密碼)

P4PORT=10.12.33.133:1700

P4USER= (你的用戶名)

 

保存退出。

c. 配置環境變量。修改后需要重啟這個才生效

用 vi 打開 /etc/profile , 末尾處加入

 

#

# pv4 config file path

#

if test -z "$P4CONFIG" ; then

export P4CONFIG=/usr/p4config/p4.configfile

fi

 

d. 測試環境配置是否成功

命令 p4 info , 如果顯示了連接信息,則 OK ,否則會提示連接不上

 

 

需要注意p4config 文件,有時候一個用戶會在自己的home目錄下建立多個client,如果在一個目錄下有多個子目錄,每一個子目錄都是一個新的client,那么每一個client都應該提供一個p4config文件;

如果只是提供一個p4config文件,那么那個p4config文件中指定的p4 client作為當前client,而無法使用另外一個client。

 

//創建相同client配置的另外一個client,可以使用前一個client作為template,這樣client文件可以自動修改

p4 client -t template_client new_client

 

 

3. 配置源代碼環境

使用命令 p4 client 會有如下信息顯示

 

Client: 你 上面配置的工作空 間

Update: 2010/01/19 20:38:36

Access: 2010/01/21 02:57:38

Owner: 你 的用 戶 名

Host: linux

Description:

Created by ygxu.

Root: /home/hammer

Options: noallwrite noclobber nocompress unlocked nomodtime normdir

SubmitOptions: submitunchanged

LineEnd: local

View:

….

//XMS/SS7_Mainline/... //Arthur_Xms/XMS/SS7_Mainline/...

….

 

兩個地方需要修改:

a . Root . 這個決定你的代碼會放在什么地方,如上,我的是 /home/hammer

b. View. 這個決定你需要取哪些代碼下來,因為一般不會把全部代碼取下來,在 Linux 上我們一般只需要 XMS 的 SS7_Mainline, 所以把其他的刪掉,修改成上面這個樣子

 

注意事項,一定要保證空間足夠,建議先刪掉原來的 SS7_Mainline ,使用 Shrink 工具回收空間之后再取代碼。

好了,使用 p4 sync 命令吧,就可以繼續工作了!

關於 p4 的使用命令,文檔如下:

http://www.perforce.com/perforce/technical.html

更詳細的命令格式參考 http://www.perforce.com/perforce/products/p4.html

p4客戶端下載 http://www.perforce.com/perforce/downloads/index.html

*************************************************************************************************************************

快速上手perforce

perforce是什么?參考http://www.perforce.com

[概念]
先說說概念吧,一般來說版本控制軟件都會分client和server,server負責做一些管理代碼和文檔倉庫,控制各個用戶的權限,記錄版本升級歷 史之類的事情,client使用某種客戶端連入server來完成代碼、文檔的修改、提交等工作,perforce也不例外。在server端 perforce做得很精簡,沒有太多的依賴,一個p4d搞定,配置起來也很簡單,它的主要任務就是管理一個文件倉庫depot。在client端有 user和workspace兩個概念,user顧名思義就是在server上登記的一個用戶,每個user可以擁有零個或者多個workspace,甚 至也可以switch到別人的workspace上去,只要有權限。簡單的說workspace是depot到本地的一個映射,例如這樣寫 //depot/foo/... //myspace/bar/...就把depot里面foo目錄下面所有東西映射到本地bar目錄里面去了,myspace是和特定的 workspace相關的,在設置workspace的時候可以設置它的絕對路徑。

[連接之前的配置]
首先我們需要一個用戶,假設已存在一個用戶test,沒有密碼。
$P4CONFIG=p4conf.conf; export P4CONFIG
windows下使用
p4 set P4CONFIG=p4conf.conf
這個命令設置一個環境變量P4CONFIG,文件名可以自己定義,里面可以存放客戶端的配置。在UNIX系統中配置信息都可以寫道環境變量里,windows下可以都寫到注冊表里去,不過我更傾向於在某一個目錄下面建立一個配置文件,這樣可以很方便的切換不同的workspace。然后我們就可以開始編輯這個p4conf.conf配置文件,格式很簡單都是 setting=value 形式的。
建立一個workspace目錄,在里面新建一個p4conf.conf文件,內容如下:
P4PORT=192.168.0.1:1666
P4USER=test
P4CLIENT=test-client
這是一個最簡單的配置文件,P4PORT指名了服務器的ip和端口,ip也可以用計算機名代替,例如
P4PORT=p4server:1666
如果留空 P4PORT=1666 這樣代表默認連接本地的server,如同 P4PORT=127.0.0.1:1666一樣。
P4USER是用戶名,P4CLIENT是當前是用的workspace名字,這個名字可以任意取,僅僅是一個標識。
這時候就可以cd到這個目錄運行一下
$p4 info
看看輸出是什么,如果顯示了如下內容
User name: test
Client name: test-client
Client host: computername
Client unknown.
Current directory: /home/test/workspace
Client address: 127.0.0.1:1508
Server address: 192.168.0.1:1666
Server root: .
Server date: 2006/07/26 00:28:12 +0800 China Standard Time
Server version: P4D/NTX86/2006.1/102189 (2006/06/27)
Server license: none
就表示成功連上服務器了,如果出現像這樣的錯誤,那就要檢查一下P4PORT有沒有設置正確
Perforce client error:
Connect to server failed; check $P4PORT.
TCP connect to 1666 failed.
connect: 1666: WSAECONNREFUSED
到這兒,最基本的client配置已經完成,很簡單吧:-) 在配置文件里還可以存放一些其他的設置,例如
P4EDITOR指定在編輯的時候默認使用這個vim編輯器,P4DIFF指定了比較文件的時候使用的工具,
P4PASSWD當用戶需要密碼的時候可以提供一個默認密碼,其他還有一些可以參考官方文檔 P4 User's Guide

[連接之后的配置]
之前的所有設置都是保存在環境變量,配置文件或者注冊表里面的,這僅僅定義了一個客戶端的行為,很大一部分事情例如追蹤用戶的修改、打開、提交的文件之類都是由服務器記錄下來的,所以現在我們需要通過一些命令來配置一下服務器那頭的用戶信息。
$p4 user
這個命令的結果是p4使用一個默認的編輯器打開一個臨時文件,文件中保存着用戶的一些信息,例如用戶名,Email,FullName之類,用戶可以自己 修改其中某些設置,保存以后它會自動提交到服務器上更新用戶設置。這個過程中使用的編輯器可以在環境變量或者配置文件中指定(P4EDITOR)。
$p4 client
和上面一樣,這個命令編輯一個client的配置文件。Root對應於workspace在本機上的絕對路徑,Options定義了一些client的屬 性,例如unlocked值允許其他的用戶switch到你的工作空間,其他的定義可以參考官方文檔。View的配置比較重要,它定義了服務器上面的文件 到workspace的映射。例如
//depot/... //test-client/...
左右分別代表源地址和目的地址,中間以空格隔開,它的意思是將服務器depot里面所有文件映射到我的工作目錄(在這之前用Root參數指定的絕對路徑)。映射可以有多行:
//depot/src/... //test-client/local-src/...
//depot/doc/... //test-client/local-doc/...
這樣就將代碼和文檔分別映射到本地,而且不一定要和服務器上使用相同的名字。在這之中也許會有需要排出的一些文件或者目錄,這時只需要在映射前面加上一個減號:
-//depot/doc/file1.txt //test-client/local-doc/file1.txt
這樣就排除了一個文件。在這個過程中要留意出現沖突,如下:
//depot/src/... //test-client/src/...
//depot/doc/... //test-client/src/...
將服務器上兩個目錄都映射到本地同一個目錄。
上面的過程中使用了一種通配符“...”它遞歸的匹配這個目錄以及子目錄下面的所有文件,另一種上面沒有使用的 “*” 匹配單個目錄下的文件,例如 //test-client/src/*.c 匹配 src目錄下面所有以 .c 作為擴展名的文件。
上面說了,如果把服務器上的兩個目錄都映射到本地通一個目錄會產生沖突,后者會把前者覆蓋,但如果這樣寫:
//depot/src/... //test-client/local-src/...
+//depot/doc/... //test-client/local-src/...
就會產生不同的效果,兩個目錄里面的文件都會出現在local-src這個目錄中,不過如果仍然有重名的文件則后者會把前者覆蓋。
至此,client的配置基本上完成,可以 $p4 sync 一下把服務器上的東西抓下來看看:-)
另外,如果要刪除這個cient的話很簡單 $p4 client -d test-client 就可以了

[文件管理]
配置了這么半天,現在開始步入正題,文件的管理才是我們使用perforce的核心工作。簡單的說,文件操作可以分成三類:往depot里面添加文件,修改並提交文件和刪除文件。
在這之前最好保證workspace里面文件和服務器上的最新版本同步,使用命令:
$p4 sync ...
如果需要同步到某一個版本,在后面添上 #1 數字代表版本號;如果需要強制同步所有文件,可以加上 -f 參數。關於sync的具體用法可以用命令
$p4 help sync
btw: 可以試試看$p4 help help

添加文件:
$p4 add *.txt
將當前目錄下所有擴展名為txt的文件添加到depot相應目錄,注意在添加文件的時候不可以使用通配符 ... 因為 ... 有服務器負責解析,這時候服務器並不知道需要添加什么文件,但卻可以使用 * ,它是由shell負責解析。
另外,所有修改在submit之前都不會提交到服務器。

修改文件:
$p4 edit //depot/src/a.c
這個文件執行以后在服務器上就會記錄下當前的 client已經在編輯這個文件,在本地只有一個動作,就是將a.c文件的只讀屬性去掉,這時候我們就可以隨便使用某種編輯器來編輯這個文件了,在這之前所有文件都是只讀的,而且不要手動去掉只讀屬性來編輯,因為那樣服務器跟蹤不到client的修改記錄。

刪除文件:
$p4 delete //depot/doc/a.pdf
注意在submit之前這個文件在服務器上也是不會被刪除的。

撤銷修改:
$p4 revert *.txt
這會將之前所有添加的或者修改的,以txt作為擴展名的文件全部撤銷到原先的狀態,原先添加的文件會被刪除,修改的文件被還原到執行p4 sync時候的版本。
最后我們可以將上面所有修改全部提交:
$p4 submit
這時候p4會調用默認的或者P4EDITOR所指定的編輯器來編輯一個配置文件,里面包含了提交者的信息,對這次提交的描述以及列舉出涉及到的文件等,一般來說把Description一項填充完保存就可以了。然后會看到屏幕上嘩啦嘩啦的輸出一堆東西,最后顯示 Change xxxx submitted. 就表示這次提交成功了。如果出現錯誤,有可能是存在沖突或者別的情況,關於沖突的問題留着后面再說~~_~~
文件之間的diff:
$p4 diff file
$p4 diff2 file1 file2
前者在client端進行比較,使用client端配置的工具,相對於perforce自帶的diff我還是更喜歡vimdiff :-)后者在server端比較,返回兩個文件(也可能是很多文件)之間的比較結果。
離線工作:
在線工作的時候所有文件的修改都由服務器來記錄,文件的讀寫權限設置也是和服務器上同步的,但是一但離線就需要用另一種方法來管理workspace里面的文件了。
首先需要對那些等待修改的文件手動去掉只讀屬性,然后可以開始修改,等到和服務器建立連接的時候需要做兩件事情:
1 找到所有修改過的文件,open for edit
$p4 diff -se | p4 -x - edit
2 找到所有刪除的文件, open for delete
$p4 diff -sd | p4 -x - delete
最后 submit 就可以

下面是perforce diff詳述:

概述
對一個客戶工作區中的文件和一個版本庫中的文件版本進行比較
語法
p4 [g-opts] diff [-dflag -f -m max -sa -sb-sd -se -sr -sl -t] [file[rev#]...]
描述
p4 diff 命令在Perforce客戶端上運行一個diff程序, 對客戶工作區中的文件和版本庫中的版本文件進行比較。
個命令需要一個包含版本標識符的文件參數。如果包含了一個版本標識符,在客戶工作區的文件會與該指定的版本文件進行比較。如果沒有包含版本標識符,那么客戶工作區的文件會與當前被編輯的版本(通常是最新的版本)進行比較。在這兩種情況中,客戶的文件都必須被打開編輯,或比較必須是對客戶文件最后一個同步版本不同的版本文件進行比較。
如果文件名包括通配符,那么所有打開得匹配該模板的文件都會被比較。如果沒有提供文件參數,那么所有打開的文件會與他們在版本庫中的相應文件進行比較。
缺省情況下,diff 程序使用的是內建在p4客戶程序中的。如果要改變diff 程序去運行一個外部程序,那么設置P4DIFF 環境變量或注冊一個變量來指向這個新的程序。
選項
-f

強制進行比較 (如果沒有版本標識符,那么於最新版本比較),即使客戶文件沒有打開進行編輯
-dflags

傳遞選項給后面的diff 程序 (閱讀下面的使用提示)
-m max
限定輸出顯示diffs(or status) 的第一個max 文件


-sa

只顯示那些打開的與版本庫里版本文件不同或不存在的文件的名字

-sb

只顯示打開得已解析過給集成的,但是在解析后背修改過的文件的名字

-sd

只顯示那么沒有打開得沒有存在與客戶工作區中,但是在版本庫中存在的文件的名字。
-se

只顯示沒有打開的在客戶工作區中但是與版本庫中版本不同的文件的名字

-sr

只顯示那些在客戶工作區中打開的用來標識版本庫中版本的文件的名字。

-sl file...

所有打開的文件與版本庫進行比較,然后顯示三種狀態 same, diff, missing.中的一種
If you use the -f flag together with the-sl flag, files that are open for edit are also compared and their status islisted.

-t
比較甚至文件類型不是文本類型的文件的不同
g-opts 閱讀 全局選項部分

使用提示
Can File Arguments Use Revision Specifier?

YES
Can File Arguments Use Revision Range?

NO
Minimal Access Level Required
read

p4 diff 支持的diff 選項有:
選項
名字
-dn
RCS輸出格式,顯示文件中增加的和刪除的以及相關行的內容
-dc
文本輸出格式,顯示行編號范圍和三行變更內容
-ds
總結輸出格式,只顯示總共增加,刪除或修改的行數量
-du
unifiedoutput format, showing added and deleted lines with sufficient context forcompatibility with the patch(1) utility.
-dl
ignoreline-ending (CR/LF) convention when finding diffs
-db
ignorechanges made within whitespace; this flag implies -dl.
-dw
ignorewhitespace altogether; this flag implies -dl.
l
為了傳遞超過一個的選項給diff程序,可以打包他們。例如:
p4 diff -dub file
specifies a unified diff that ignores changes in whitespace.
l
?
The header line of a unifieddiff produced with the -du option for use with patch(1) displays filenames inPerforce syntax, not local syntax.
舉例
p4 diff file#5

將客戶工作區中的“file”與版本庫中的第五版本進行比較
p4 diff @1999/05/22

將客戶工作區中所有打開得文件與版本庫中May 22, 1999修改的版本進行比較.
p4 diff -du file
file 進行比較,顯示符合patch(1) utility格式的輸出.
p4 diff -sr | p4 -x - revert
恢復所有打開得沒有修改過的文件。
This differs from p4 revert -a ( revert allunchanged files, where resolving a file, even if no changes are made, counts asa change), in that it reverts files whose workspace content matches the depotcontent, including resolved files that happen to be identical to those in thedepot.
第一個命令顯示所有打開得沒有修改過的文件。The second command (running p4 -x and taking arguments, one perline, from standard input, abbreviated as "-") reverts each file inthat list.
(This is the UNIX version of this command;it uses a pipe. Most operating systems have some equivalent way of performingthese operations in series).
p4關於 -x 選項的更多信息,閱讀 全局選項 部分

相關命令
比較兩個版本庫中的文件版本的不同
p4 diff2
查看一個文件的全部內容
p4print
************************************************************************************************************************************

Perforce使用中文教程: p4 diff2

Perforce 命令: p4 diff2

概述
比較版本庫中文件的兩個版本
語法
p4 [g-opts] diff2 [-dflags -q -t -u]file1[rev] file2[rev]
p4 [g-opts] diff2 [-dflags -q -t -u] -bbranch [[fromfile[rev]] tofile[rev]]
描述
p4 diff2 命令使用Perforce 服務器中內建的diff 程序對版本庫中的倆個文件版本進行比較。這些版本通常是指同一個文件的兩個不同的版本,但是他們也可以是兩個完全不同文件的版本。如果沒有沒有提供版本給文件參數,那么最新的版本被用來比較。
p4 diff2 不使用由環境變量P4DIFF 定義的diff 程序。p4 diff 命令使用的diff 算法在裝有Perforce 服務器機器上運行,而且一直使用服務器內建的diff 程序
可以在指定文件參數的位置指定一個有(或沒有)版本標識的文件模版;這樣可以導致Perforce 對那些匹配模版的成對文件執行diff 命令。如果你調用使用文件模版的p4 diff2 命令,使用引號或反斜線可以從OS 外殼中退出文件模版,那么確定在兩個模版中的通配符相匹配。
Perforce presents the diffs in UNIX diffformat, prepended with a header. 起始部分的格式如下:
==== file1 (filetype1) - file2 (filetype2)==== summary
summary 可能出現的值和意義如下:
content: 文件版本的不同內容
types: 內容完全相同, 但是文件類型不同
identical: 版本的內容和文件類型都相同
如果文件file1 file2 在指定的版本中不存在,那么起始部分將顯示summary <none>.
選項
-q
Quietdiff.
只顯示表頭部分,並且在文件版本內容和類型不同時也不顯示內容
-dflags

把標准的UNIX diff 選項之一作為參數運行diff 程序。閱讀 后面的《使用提示》
-b branchname
fromfile[rev] tofile[rev]
使用一個分支的定義去比較在兩個分支代碼行里的文件。被比較的文件可以被文件模版中的 fromfile tofile 里的任意一個所限定
-t

比較甚至文件類型不是文本類型的文件的不同
-u
Generateunified output format, showing added and deleted lines with sufficient contextfor compatibility with the patch(1) utility. Only those files that differ areincluded. File names and dates remain in Perforce syntax.
g-opts
閱讀 全局選項 部分
使用提示
Can File Arguments Use Revision Specifier?

Yes
Can File Arguments Use Revision Range?

NO
Minimal Access Level Required
readaccess necessary for both file revisions

The diff flagssupported by p4 diff2 are:
選項
名稱
-dn
RCS 輸出格式, 顯示文件中增加的和刪除的以及相關行的內容
-dc
文本輸出格式, 顯示行編號范圍和三行變更內容
-ds
總結輸出格式,只顯示總共增加,刪除或修改的行數量
-du
unified 輸出格式 showing added and deleted lines with sufficient context forcompatibility with the patch(1) utility.
-db
忽略在空格中做的改變
-dw
忽略連在一起的空格
為了傳遞超過一個的選項給diff 程序,可以打包他們。例如
p4 diff2 -dub file1 file2
specifies a unified diff that ignoreschanges in whitespace.
The header lineof a unified diff produced with the -du option for patch(1) use displays thediffed files in Perforce syntax, not local syntax.


p4 diff2 命令被用來對比較二進制文件時, 該行
... files differ ...
會被顯示出來,如果他們沒有被識別的話。
選項 -b branch [[fromfile[rev]] tofile[rev] ] 在第一次看見是可能覺得不正確。Since the branch specification maps fromfiles to tofiles, why wouldyou specify both fromfile and tofile file patterns? You wouldn't, but thissyntax allows you to specify a fromfile file pattern and a tofile revision, ora fromfile revision and a tofile file pattern.
舉例
p4 diff2 -ds file#1 file

比較 file 文件的第二個版本和最新版本,並顯示文件中內容被添加,更改或刪除的信息
p4 diff2
file@34 file@1998/12/04
Diff the revision of file that was in thedepot after changelist 34 was submitted against the revision in the depot atmidnight on December 4, 1998.
p4 diff2
//depot/rel1/... //depot/rel2/...#4

比較在版本庫 //depot/rel1 中的所有最新文件與版本庫 //depot/rel2 第四個版本文件
p4 diff2
//depot/rel1/* //depot/rel2/...

不允許。每個文件的通配符模式必須匹配
p4 diff2
-b branch2 //depot/rel2/...#2 @50
Compare the second revision of the filesin //depot/rel2/... to the files branched from it by branch specificationbranch2 at the revision they were at in changelist 50.
相關命令
比較客戶工作區中文件與版本庫中的版本文件
p4 diff

查看一個文件的全部內容
p4 print

 

 

 

 

 

command 附錄:

 

p4 add Open a new file to add it to the depot

p4 admin Perform administrative operations on the server

p4 annotate Print file lines along with their revisions

p4 branch Create or edit a branch specification

p4 branches Display list of branches

p4 browse Browse for a list of Zeroconf-registered Perforce servers

p4 change Create or edit a changelist description

p4 changes Display list of pending and submitted changelists

p4 changelist Create or edit a changelist description

p4 changelists Display list of pending and submitted changelists

p4 client Create or edit a client specification and its view

p4 clients Display list of known clients

p4 copy Makes target identical to source by branching, replacing or deleting

p4 cstat Lists the changes not synchronized in the current client

p4 counter Display, set, or delete a counter

p4 counters Display list of known counters

p4 dbschema Report information about metadata in the Perforce database

p4 dbstat Display size or simple statistics for a database table

p4 delete Open an existing file to delete it from the depot

p4 depot Create or edit a depot specification

p4 depots Display list of depots

p4 describe Display a changelist description

p4 diff Display diff of client file with depot file

p4 diff2 Display diff of two depot files

p4 dirs List subdirectories of a given depot directory

p4 edit Open an existing file for edit

p4 export Extract journal or checkpoint records

p4 filelog List revision history of files

p4 files List files in the depot

p4 fix Mark jobs as being fixed by named changelists

p4 fixes List what changelists fix what job

p4 flush Fake a ‘p4 sync’ by not moving files

p4 fstat Dump file info

p4 grep Print lines in files (or revisions of files) that match a pattern

p4 group Change members of a user group

p4 groups List groups (of users)

p4 have List revisions last synced

p4 help Print this help message

p4 info Print out client/server information

p4 interchanges Lists changes not yet integrated from source to target

p4 integrate Schedule integration from one file to another

p4 integrated Show integrations that have been submitted

p4 istat Shows the stream’s integration status

p4 job Create or edit a job (defect) specification

p4 jobs Display list of jobs

p4 jobspec Edit the job template

p4 label Create or edit a label specification and its view

p4 labels Display list of labels

p4 labelsync Synchronize label with the current client contents

p4 license Update or display the license file

p4 lock Lock an opened file against changelist submission

p4 lockstat Report lock status of database tables

p4 logger Report what jobs and changelists have changed

p4 login Login to Perforce by obtaining a session ticket

p4 logout Logout of Perforce by removing or invalidating a ticket

p4 logstat Report size of journal, error log, and/or audit log files

p4 logtail Display the last block(s) of the error log

p4 merge Merge changes from one set of files into another

p4 monitor Display current running Perforce process information

p4 move Move file(s) from one location to another

p4 obliterate Remove files and their history from the depot

p4 opened Display list of files opened for pending changelist

p4 passwd Set user password on server (and Windows client)

p4 print Retrieve a depot file to the standard output

p4 protect Modify protections in the server namespace

p4 protects Display protections in place for a given user/path

p4 rename Explains how to rename files

p4 reopen Change the type or changelist number of an opened file

p4 replicate Replicate server metadata from one server to another

p4 resolve Merge open files with other revisions or files

p4 resolved Show files that have been merged but not submitted

p4 revert Discard changes from an opened file

p4 review List and track changelists (for the review daemon)

p4 reviews Show what users are subscribed to review files

p4 shelve Store files from a pending changelist, without submitting them

p4 set Set variables in the registry (Windows only)

p4 sizes Display size information for files in the depot

p4 stream Create or edit a stream specification

p4 streams Display a list of known streams

p4 submit Submit open files to the depot

p4 sync Synchronize the client with its view of the depot

p4 tag Tag files with a label

p4 tickets Display list of session tickets for this user

p4 triggers Modify list of pre-submit and form-validating triggers

p4 typemap Modify the file name-to-type mapping table

p4 unlock Release a locked file but leave it open

p4 unshelve Restore shelved files from a pending change into a workspace

p4 user Create or edit a user specification

p4 users Display list of known users

p4 verify Verify that the server archives are intact

p4 where Show how file names map through the client view

p4 workspace Create or edit a client specification and its view

p4 workspaces Display list of known clients

 

問題解決:

1. 有時候client里面會有一些null changelist,這樣當運行p4 client -d xxx的時候會不允許刪除client,錯誤信息,"use -f force delete client".

 解決方法: 假設當前要刪除的client名稱為 client_xxx.

             首先list所有的null changelist :

                  p4 changes -c client_xxx -s pending

             再刪除這些pending的changelist:

                  p4 change -d ####

 

             有些時候,當使用rm -rf xxx刪除目錄的時候不允許刪除,原因在於目錄屬性:

                  chmod -R 777 xxx_dir

             再來刪除目錄。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM