以前曾提到過(guò),在發(fā)布軟件補(bǔ)丁時(shí)很少(可能從不)使用正規(guī)和并排的塊格式.但diff產(chǎn)生的上下文(context)或統(tǒng)一(unified)的塊格式是創(chuàng)建補(bǔ)丁所采用的格式.為了產(chǎn)生上下文的差異文件(它們稱為context
diff的原因是它們顯示出了有差別的行的上下文內(nèi)容),可使用diff的-c或-C[num]選項(xiàng).
提示:和大多數(shù)GNU程序一樣,diff也支持長(zhǎng)選項(xiàng),也就是以兩個(gè)兩字符"--"開(kāi)頭,后面跟著更容易記憶的名字的選項(xiàng),例如,創(chuàng)建一個(gè)上下文diff文件的長(zhǎng)選項(xiàng)是"--context=[num]".
上下文輸出舉例
$diff -c hello.c howdy.c
*** hello.c Web Aug 9 21:02:42 2000
--- howdy.c Web Aug 9 21:04:30 2000
*************
*** 1,12 ****
#include <stdio.h>
int main(void)
{
! char msg[ ] = "Hello, Linux programmer!";
puts(msg);
! printf("Here you are, using diff.\n");
! return 0;
}
--- 1,13 ---
#include <stdio.h>
+ #include <stdlib.h>
int main(void)
{
! char msg[] = "Hello, Linux programmer, from howdy.c!");
puts(msg);
! printf("howdy.c says, `Here you are, using diff.`\n");
! exit(EXIT_SUCCESS);
}
$
上下文塊的格式采用以下一般形式:
*** srcfile srcfile_timestamp
--- dstfile dstfile_timestamp
****************
*** srcfile_line_range ***
srcfile line
--- dstfile line_line_range
dstfile line
dstfile line...
. + -----向srcfile添加一行以創(chuàng)建dstfile
. - -----從srcfile刪除一行以創(chuàng)建dstfile
. ! -----在srcfile改變一行以創(chuàng)建dstfile.srcfile中標(biāo)記"!"的每一行或一段,在dstfile中相應(yīng)的每一行或一段也標(biāo)記"!".
每一塊(hunk)都用一長(zhǎng)串最多15個(gè)星號(hào)和下一塊(hunk)分隔開(kāi)來(lái).
提示:和大多數(shù)GNU程序一樣,diff也支持長(zhǎng)選項(xiàng),也就是以兩個(gè)兩字符"--"開(kāi)頭,后面跟著更容易記憶的名字的選項(xiàng),例如,創(chuàng)建一個(gè)上下文diff文件的長(zhǎng)選項(xiàng)是"--context=[num]".
上下文輸出舉例
$diff -c hello.c howdy.c
*** hello.c Web Aug 9 21:02:42 2000
--- howdy.c Web Aug 9 21:04:30 2000
*************
*** 1,12 ****
#include <stdio.h>
int main(void)
{
! char msg[ ] = "Hello, Linux programmer!";
puts(msg);
! printf("Here you are, using diff.\n");
! return 0;
}
--- 1,13 ---
#include <stdio.h>
+ #include <stdlib.h>
int main(void)
{
! char msg[] = "Hello, Linux programmer, from howdy.c!");
puts(msg);
! printf("howdy.c says, `Here you are, using diff.`\n");
! exit(EXIT_SUCCESS);
}
$
上下文塊的格式采用以下一般形式:
*** srcfile srcfile_timestamp
--- dstfile dstfile_timestamp
****************
*** srcfile_line_range ***
srcfile line
--- dstfile line_line_range
dstfile line
dstfile line...
. + -----向srcfile添加一行以創(chuàng)建dstfile
. - -----從srcfile刪除一行以創(chuàng)建dstfile
. ! -----在srcfile改變一行以創(chuàng)建dstfile.srcfile中標(biāo)記"!"的每一行或一段,在dstfile中相應(yīng)的每一行或一段也標(biāo)記"!".
每一塊(hunk)都用一長(zhǎng)串最多15個(gè)星號(hào)和下一塊(hunk)分隔開(kāi)來(lái).