2013年11月4日 星期一

diff 參數備忘

diff 是我每次用都要查的指令@@,所以寫下來備忘一下。

diff -Naur path1 path2 > project.patch
-N    In  directory comparison, if a file is found in only one directory, treat it as present but empty in the other directory.
-a    Treat  all  files as text and compare them line-by-line, even if they do not seem to be text.
-u    Use the unified output format.
-r    When comparing directories, recursively compare any subdirectories found.


如果要使用這個 patch 檔

patch -p# < project.patch
PS: "#" 表示要省略的路徑層數

man 的原文說明
-pnum or --strip=num
  Strip the smallest prefix containing num leading slashes from each file name found in the patch file.
  A sequence of one or more adjacent slashes is counted as a single slash. This controls how file names found in the patch file are treated, in case you keep your files in a different directory than the person who sent out the patch. For example, supposing the file name in the patch file was

/u/howard/src/blurfl/blurfl.c

setting -p0 gives the entire file name unmodified, -p1 gives

u/howard/src/blurfl/blurfl.c

without the leading slash, -p4 gives

blurfl/blurfl.c

and not specifying -p at all just gives you blurfl.c. Whatever you end up with is looked for either in the current directory, or the directory specified by the -d option.

沒有留言:

張貼留言