git diff
可以用来比较:
staging area和working area的文件 (无其他参数时)
git diff
master分支和working area的文件 (用master参数)
git diff master
HEAD指向的内容和working area的文件
git diff HEAD
用远程master分支比较当前工作区
git diff refs/remotes/origin/master
某个文件的历史版本和working area的该文件的比较
git diff 0c5ee16a6a4c849d0ae0448caa8ff174399c7c3c ./socket_helper.cpp
上面的命令中, diff后面的参数指的是commit id, ./socket_helper.cpp是要比较的文件路径。
两个commit id对比
git diff 09af67bcab06ad05056ea774dcd487933deb7372 1e496003ff6377618570611c950c1ac550c3899b -- .
旧的commit id建议放在前面,新的commit id放在后面
diff的命令输出格式
---代表源文件
+++代表目标文件
通常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.其他空格开头的行表明没有差异。
diff 状态
很多时候,第一眼是要看有哪些文件变了,而不是看很多细节,可以用diff --tag参数
git diff --stat 09af67bcab06ad05056ea774dcd487933deb7372 1e496003ff6377618570611c950c1ac550c3899b -- .
dependency_network/README.org | 21 ------
dependency_network/graph.lsp | 171 -------------------------------------------------
dependency_network/graph.lsp.html | 134 --------------------------------------
dependency_network/index.html | 25 --------
dependency_network/pipeline.lsp | 15 -----
dependency_network/test/basic/test_graph.lsp | 72 ---------------------
dependency_network/test/url-counter/test.lsp | 93 ---------------------------
doc/url-counter.png | Bin 9836 -> 9544 bytes
doc/url-counter.txt | 10 +--
"doc/\350\241\200\347\274\230\345\205\263\347\263\273\347\256\241\347\220\206.html" | 47 ++++++--------
"doc/\350\241\200\347\274\230\345\205\263\347\263\273\347\256\241\347\220\206.org" | 30 ++++-----
pipeline/README.org | 21 ++++++
pipeline/graph.lsp | 171 +++++++++++++++++++++++++++++++++++++++++++++++++
pipeline/graph.lsp.html | 134 ++++++++++++++++++++++++++++++++++++++
pipeline/index.html | 25 ++++++++
pipeline/pipeline.lsp | 15 +++++
pipeline/test/basic/test_graph.lsp | 75 ++++++++++++++++++++++
pipeline/test/url-counter/test.lsp | 96 +++++++++++++++++++++++++++
18 files changed, 577 insertions(+), 578 deletions(-)