diff命令是版本管理工具的基础,本文主要讲解diff比较几种方式和git diff使用技巧。
如下两个文件,file1和file2
$ cat file1
aa
aa
aa
aa
aa
$ cat file2
aa
aa
bb
aa
aa
$ diff file1 file2
3c3
< aa
---
> bb
$ diff -c file1 file2
*** file1 2016-04-04 15:56:25.203923276 +0800
--- file2 2016-04-04 15:56:47.647138613 +0800
***************
*** 1,5 ****
aa
aa
! aa
aa
aa
--- 1,5 ----
aa
aa
! bb
aa
aa
*** file1 2016-04-04 15:56:25.203923276 +0800
--- file2 2016-04-04 15:56:47.647138613 +0800
$ diff -u file1 file2
--- file1 2016-04-04 15:56:25.203923276 +0800
+++ file2 2016-04-04 15:56:47.647138613 +0800
@@ -1,5 +1,5 @@
aa
aa
-aa
+bb
aa
aa
--- file1 2016-04-04 15:56:25.203923276 +0800
+++ file2 2016-04-04 15:56:47.647138613 +0800
@@ -1,5 +1,5 @@
diff --git a/file1 b/file1
index a57a69a..863575a 100644
--- a/file1
+++ b/file1
@@ -1,5 +1,5 @@
aa
aa
-aa
+bb
aa
aa
git diff #工作区和暂存区比较
git diff master #工作区和master分支比较
git diff HEAD #工作区和HEAD比较