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
[email protected] [email protected]/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