git diff 簡單用法
git diff ----------------用來比較,用法:
1.staging area和working area的文件 (無其他參數時)
指令:git diff
2.master分支和working area的文件 (用master參數)
指令:git diff master
3.HEAD指向的內容和working area的文件
指令:git diff HEAD
4.用遠程master分支比較當前工作區
指令:git diff refs/remotes/origin/master
5.經常還要用到master分支的某個文件的歷史版本和working area的該文件的比較
指令:git diff 0c5ee16a6a4c849d0ae0448caa8ff174399c7c3c ./socket_helper.cpp
上面的命令中, diff後面的參數指的是commit id, ./socket_helper.cpp是要比較的文件路徑。
註意:diff的命令輸出格式註意:
1.---代表源文件
2.+++代表目標文件
通常working area的文件都是被當作目標文件來看待。
-開頭的行,是只出現在源文件中的行
+開頭的行,是只出現在目標文件中的行
空格開頭的行,是源文件和目標文件中都出現的行
差異按照差異小結進行組織,每個差異小結的第一行都是定位語句,由@@開頭,@@結尾。
- chenshu@chenshu-yangzhou-home:~/kaimei/data_service/src$ git diff 0c5ee16a6a4c849d0ae0448caa8ff174399c7c3c ./socket_helper.cpp
- diff --git a/data_service/src/socket_helper.cpp b/data_service/src/socket_helper.cpp
- index d606452..047e213 100755
- --- a/data_service/src/socket_helper.cpp
- +++ b/data_service/src/socket_helper.cpp
- @@ -4,6 +4,7 @@
- #include "data/login_response.h"
- #include "data/heartbeat_response.h"
- #include "helper/parser.h"
- +#include "helper/time_measure.h"
- #include <booster/log.h>
- #include "exception/socket_error.h"
- #include "exception/data_error.h"
上面的diff結果表明
1.某個提交記錄0c5ee代表的socket_helper.cpp文件是源文件,當前working area的socket_helper文件是目標文件。
2.在源文件第4行開始的6行和目標文件第4行開始的7行構成一個差異小結
3.這個差異小結中,目標文件添加了一行#include "helper/time_measure.h"
4.其他空格開頭的行表明沒有差異。
以上是自己沒看懂書馬克大牛的,差距啊。多多努力吧
git diff 簡單用法