git diff適用於git管理的檔案。而diff命令則沒有限制。但一般系統檔案都在版本控制中,所以git diff用的比較多。
推薦diff -u
一。參數
1.diff格式參數
-u 輸出統一格式,-c是傳統格式。diff有"傳統"和"統一"兩種格式,一般使用"統一"格式,即-u . 比較而言,統一格式產生的檔案大,但包含了更多的資訊,有利於閱讀與定位
注意到-c 與-u這二種格式不能同時使用。你只能使用其中一種格式化輸出內容
diff -u -c /home/gaoyibo/php-site/php-site/src/Search/web.xml /home/gaoyibo/search/workspace/searchServer/WebContent/WEB-INF/web.xml > web.patch
diff: conflicting output style options
diff: Try `diff --help' for more information.
瞭解-u的輸出格式:同一塊內容,裡面用+,-區分檔案的修改。
--- /home/gaoyibo/php-site/php-site/src/Search/web.xml 2011-11-08 15:38:07.000000000 +0800
+++ /home/gaoyibo/search/workspace/searchServer/WebContent/WEB-INF/web.xml 2011-11-07 11:22:45.000000000 +0800
@@ -25,8 +25,9 @@
<servlet-name>InitServlet</servlet-name>
<servlet-class>com.daodao.servlet.InitServlet</servlet-class>
<init-param>
+ <!-- change path -->
<param-name>propspath</param-name>
- <param-value>/home/search/config/</param-value>
+ <param-value>/home/gaoyibo/search/resource/</param-value>
</init-param>
<init-param>
<param-name>propsname</param-name>
2.diff目錄用到參數
如果比較二個目錄,使用-r,表示Recursively compare any subdirectories found. -x 用來排除目錄中的某個檔案
**3.其它參數
-a Treat all files as text.
-b Ignore changes in the amount of white space.
-N 如果某個檔案只在一個目錄中出現,則假定在另一個目錄中為空白檔案.
查看diff -acb產生的patch檔案:
樣本1:注意下頁的樣本只為說明-c,推薦使用-u。
不會針對同行做修改。只有增減。注意,這種情況下,---檔案的變化都是在***裡使用“-”來標誌。---部分沒有內容。這與!時的情況不同。
diff -r -a -c -b -x Makefile.temp /home/gaoyibo/search/workspace/searchServer/src/com/daodao/application/search/Indexer.java /home/gaoyibo/php-site/php-site/src/Search/src/com/daodao/application/search/Indexer.java
*** /home/gaoyibo/search/workspace/searchServer/src/com/daodao/application/search/Indexer.java 2011-10-27 14:21:12.000000000 +0800
--- /home/gaoyibo/php-site/php-site/src/Search/src/com/daodao/application/search/Indexer.java 2011-11-08 15:38:07.000000000 +0800
***************
*** 1,7 ****
package com.daodao.application.search;
import java.io.BufferedOutputStream;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
--- 1,6 ----
***************
*** 62,68 ****
// private static PinYinSearchTree m_cPinYinSearchForLocation = new PinYinSearchTree();
- //
public static LinkedBlockingQueue<Document> m_lDocQueue = new LinkedBlockingQueue<Document>(200000);
--- 61,66 ----
***************
*** 106,112 ****
}
}
-
private Indexer(Properties prop)
{
_init(prop);
--- 104,109 ----
***************
*** 120,126 ****
{
prop = DaoDaoConfig.getProperties();
}
- //私人的構造方法供單例使用。
m_iInstance = new Indexer(prop);
}
return m_iInstance;
--- 117,122 ----
樣本2:對同行做修改。注意---部分格式的變化。
diff -r -a -c -b -x Makefile.temp /home/gaoyibo/search/workspace/searchServer/src/com/daodao/servlet/Init.java /home/gaoyibo/php-site/php-site/src/Search/src/com/daodao/servlet/Init.java
*** /home/gaoyibo/search/workspace/searchServer/src/com/daodao/servlet/Init.jav2011-11-08 19:51:56.000000000 +0800
--- /home/gaoyibo/php-site/php-site/src/Search/src/com/daodao/servlet/Init.java2011-11-08 19:51:46.000000000 +0800
***************
*** 32,38 ****
// DaoDaoPostDBReader.getInstance();
// get location related info
long lStart = System.currentTimeMillis();
! // DaoDaoLocationReader.getInstance();
long lSpan = System.currentTimeMillis() - lStart;
lStart = System.currentTimeMillis();
DaoDaoLogging.SERVLET.info("Loading all location info takes " + lSpan
--- 32,38 ----
// DaoDaoPostDBReader.getInstance();
// get location related info
long lStart = System.currentTimeMillis();
! DaoDaoLocationReader.getInstance();
long lSpan = System.currentTimeMillis() - lStart;
lStart = System.currentTimeMillis();
DaoDaoLogging.SERVLET.info("Loading all location info takes " + lSpan
***************
*** 48,54 ****
if (DaoDaoConfig.getStringProperty(GEOPREFIXSEARCH).equalsIgnoreCase(
"true")) {
! // GeoPrefixSearch.getInstance();
lSpan = System.currentTimeMillis() - lStart;
lStart = System.currentTimeMillis();
DaoDaoLogging.SERVLET.info("Loading all geo prefix index takes "
--- 48,54 ----
if (DaoDaoConfig.getStringProperty(GEOPREFIXSEARCH).equalsIgnoreCase(
"true")) {
! GeoPrefixSearch.getInstance();
lSpan = System.currentTimeMillis() - lStart;
lStart = System.currentTimeMillis();
DaoDaoLogging.SERVLET.info("Loading all geo prefix index takes