git 工具的使用总结(5)-查看历史记录

1.查看历史记录git log

1)不加参数,显示的就是节点号,作者,日期,注释

commit b7b310d220628530d1feb9e8046ccb59039d59f2
Author: zhangshuli 
Date:   Sat Feb 28 14:25:11 2015 +0000

    cherry-pick

commit ac63f3e801e4022b34ba14ed9d1ae75b022ff067
Merge: 02906a1 618011f
Author: zhangshuli 
Date:   Sat Feb 28 14:18:04 2015 +0000

    Merge branch 'third' into parent

commit 02906a15dc15be5fefd5e41dcd3977bb2f762cff
Author: zhangshuli 
Date:   Sat Feb 28 14:10:45 2015 +0000

    yahe

commit 618011fc23e6fe8108e830e2812a298ad217d0cb
Author: zhangshuli 
Date:   Sat Feb 28 14:08:45 2015 +0000

    commit ddd

2)如果想要查看版本代码差异,可以加参数p   git log -p

commit b7b310d220628530d1feb9e8046ccb59039d59f2
Author: zhangshuli 
Date:   Sat Feb 28 14:25:11 2015 +0000

    cherry-pick

diff --git a/aaa.txt b/aaa.txt
index 7b6d3c6..3de9291 100644
--- a/aaa.txt
+++ b/aaa.txt
@@ -1,3 +1,4 @@
 my second commit
 add son
+cherry-pick
 

commit ac63f3e801e4022b34ba14ed9d1ae75b022ff067
Merge: 02906a1 618011f
Author: zhangshuli 
Date:   Sat Feb 28 14:18:04 2015 +0000

    Merge branch 'third' into parent

commit 02906a15dc15be5fefd5e41dcd3977bb2f762cff
Author: zhangshuli 
Date:   Sat Feb 28 14:10:45 2015 +0000

    yahe

diff --git a/ccc.txt b/ccc.txt
new file mode 100644
index 0000000..b2a7546
--- /dev/null
+++ b/ccc.txt
@@ -0,0 +1 @@
+ccc
diff --git a/ddd.txt b/ddd.txt
new file mode 100644
index 0000000..1d60b70
--- /dev/null
+++ b/ddd.txt
@@ -0,0 +1 @@
+ddd

3)从开始到指定节点的历史记录 git log number

zhangshuli@zhangshuli-MS-7817:~/myGit$ git log -p 618011fc23e6fe8108e830e2812a298ad217d0cb
commit 618011fc23e6fe8108e830e2812a298ad217d0cb
Author: zhangshuli 
Date:   Sat Feb 28 14:08:45 2015 +0000

    commit ddd

diff --git a/ddd.txt b/ddd.txt
new file mode 100644
index 0000000..1d60b70
--- /dev/null
+++ b/ddd.txt
@@ -0,0 +1 @@
+ddd

commit 6a74382c9c481515cd70136ce3212ace7aa1c50e
Author: zhangshuli 
Date:   Sat Feb 28 14:08:24 2015 +0000

    commit ccc.txt

diff --git a/ccc.txt b/ccc.txt
new file mode 100644
index 0000000..b2a7546
--- /dev/null
+++ b/ccc.txt
@@ -0,0 +1 @@
+ccc

4)查找制定范围历史记录

git log number1..number2(两个节点的历史记录,不包括前节点,包括后节点)

zhangshuli@zhangshuli-MS-7817:~/myGit$ git log -2
commit b7b310d220628530d1feb9e8046ccb59039d59f2
Author: zhangshuli 
Date:   Sat Feb 28 14:25:11 2015 +0000

    cherry-pick

commit ac63f3e801e4022b34ba14ed9d1ae75b022ff067
Merge: 02906a1 618011f
Author: zhangshuli 
Date:   Sat Feb 28 14:18:04 2015 +0000

    Merge branch 'third' into parent
zhangshuli@zhangshuli-MS-7817:~/myGit$ git log ac63f3e801e4022b34ba14ed9d1ae75b022ff067..
commit b7b310d220628530d1feb9e8046ccb59039d59f2
Author: zhangshuli 
Date:   Sat Feb 28 14:25:11 2015 +0000

    cherry-pick
zhangshuli@zhangshuli-MS-7817:~/myGit$ 

git log --since="5 hours"(支持的参数有 "2 minute" "2008-10-01" ,--before的用法也是如此)

zhangshuli@zhangshuli-MS-7817:~/myGit$ git log --since="2 minute"
zhangshuli@zhangshuli-MS-7817:~/myGit$ git log --since="2 hours"
commit b7b310d220628530d1feb9e8046ccb59039d59f2
Author: zhangshuli 
Date:   Sat Feb 28 14:25:11 2015 +0000

    cherry-pick

commit ac63f3e801e4022b34ba14ed9d1ae75b022ff067
Merge: 02906a1 618011f
Author: zhangshuli 
Date:   Sat Feb 28 14:18:04 2015 +0000

    Merge branch 'third' into parent

commit 02906a15dc15be5fefd5e41dcd3977bb2f762cff
Author: zhangshuli 
Date:   Sat Feb 28 14:10:45 2015 +0000

    yahe

commit 618011fc23e6fe8108e830e2812a298ad217d0cb
Author: zhangshuli 
Date:   Sat Feb 28 14:08:45 2015 +0000

    commit ddd

commit 6a74382c9c481515cd70136ce3212ace7aa1c50e
Author: zhangshuli 
Date:   Sat Feb 28 14:08:24 2015 +0000

    commit ccc.txt

commit 2a30fca479f7a953d9348067670f292780d49515
Author: zhangshuli 
Date:   Sat Feb 28 14:05:12 2015 +0000

    change
zhangshuli@zhangshuli-MS-7817:~/myGit$

5)设定显示格式

git log --pretty=format:"%h %s" 1.0..HEAD

git log --pretty=oneline

zhangshuli@zhangshuli-MS-7817:~/myGit$ git log --pretty=format:"%h %s"
b7b310d cherry-pick
ac63f3e Merge branch 'third' into parent
02906a1 yahe
618011f commit ddd
6a74382 commit ccc.txt
2a30fca change
44d288e Merge branch 'thrid' into parent
6436f0b merge
ece2e62 tar zip
e2e09c4 son rebase
3a1cbb4 ccc add
5ad0d1e parent test
abbb929 branch test
2e32a61 master add
f73968d my second commit
4c7cede my frist commit
zhangshuli@zhangshuli-MS-7817:~/myGit$ git log --pretty=oneline
b7b310d220628530d1feb9e8046ccb59039d59f2 cherry-pick
ac63f3e801e4022b34ba14ed9d1ae75b022ff067 Merge branch 'third' into parent
02906a15dc15be5fefd5e41dcd3977bb2f762cff yahe
618011fc23e6fe8108e830e2812a298ad217d0cb commit ddd
6a74382c9c481515cd70136ce3212ace7aa1c50e commit ccc.txt
2a30fca479f7a953d9348067670f292780d49515 change
44d288e4316e47ac9b6e3ee6a4152aceff5d17ce Merge branch 'thrid' into parent
6436f0b6bbe0da18ce65e90dd7ea90cf4008bbe3 merge
ece2e62de24d0262c9cb70a59aeb7f2764316225 tar zip
e2e09c4898f9246b1d0fab2dc6845506f5960742 son rebase
3a1cbb43f8d1bd5224529122b15fd1fcf682b60d ccc add
5ad0d1ece9b7fd69a9e4deb990c8a4d05d2cbee1 parent test
abbb92978273479688bda512ba5e7d78b1dbf803 branch test
2e32a615216de70720d314b8fe53c1bddccfd6a3 master add
f73968df521e48d23289c5563f7ac7fbc5937b57 my second commit
4c7cede87be37783ca4528fbdcd79bc08e3870fe my frist commit
zhangshuli@zhangshuli-MS-7817:~/myGit$ 

6)根据作者提交来查询 git log --author=huangfukun

这个搜索的是关键字,你用kern也能搜到相同的结果,如下

zhangshuli@zhangshuli-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log --author=huangfukun 
commit f47dfc31da7a676c53332a79bbb35ec402c550e2
Author: Kern 
Date:   Thu Nov 13 15:14:42 2014 +0800

    merge Fun UI from platform_kk_95_ds
    
    Change-Id: Iabc3762bb332a75f5f6a5612295e77a4ca4851a0
zhangshuli@zhangshuli-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log --author=kern
zhangshuli@zhangshuli-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log --author=Kern
commit f47dfc31da7a676c53332a79bbb35ec402c550e2
Author: Kern 
Date:   Thu Nov 13 15:14:42 2014 +0800

    merge Fun UI from platform_kk_95_ds
    
    Change-Id: Iabc3762bb332a75f5f6a5612295e77a4ca4851a0
zhangshuli@zhangshuli-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$ git log --since="2014-12-13"
commit 50a7ca4c3c002670983c0c54e3d86ef1a43a1a9b
Merge: ebcc95e 60e5ceb
Author: scm2 
Date:   Sat Dec 27 17:21:16 2014 +0800

    Merge remote-tracking branch 'remotes/origin/vtrunk' into HEAD

commit 60e5ceb4615e2b227b723123a1e16dab95af351a
Author: tanglei 
Date:   Thu Dec 25 22:58:07 2014 +0800

    implement #113990, wakeup screen when receive mms
    
    Change-Id: Ie459687e5460b05625f7b3389f98684190e72a17

commit ebcc95e8d3c8e1cb0d14570cc7eb7791cbb7aef9
Merge: f47dfc3 68397e8
Author: scm2 
Date:   Tue Dec 16 10:37:20 2014 +0800

    Merge remote-tracking branch 'remotes/origin/vtrunk' into HEAD

commit 68397e8b8f7149d81f270e6a6ca3dbe72fffa80b
Merge: 5c238f7 05bed8e
Author: scm2 
Date:   Tue Dec 16 10:37:20 2014 +0800

    Merge remote-tracking branch 'remotes/origin/master' into HEAD
zhangshuli@zhangshuli-MS-7817:~/PROJECT/PROJECT_V5/32_kk_qhd_k25/packages/apps/Mms$

 

 

另外,有两个符号需要说明下

^:这个表示的是回溯,如HEAD^指得就是当前版本的前一个版本,HEAD^^(=HEAD^2)

~: 跟^ 的用法类似

不过,不知道为什么如下的方法不正确

zhangshuli@zhangshuli-MS-7817:~/myGit$ git diff --stat HEAD~4
 aaa.txt           |    1 +
 ccc.txt           |    1 -
 ddd.txt           |    2 +-
 merge.txt         |    1 -
 mysite-1.0.tar.gz |  Bin 501 -> 0 bytes
 mysite-1.0.zip    |  Bin 501 -> 0 bytes
 6 files changed, 2 insertions(+), 3 deletions(-)
zhangshuli@zhangshuli-MS-7817:~/myGit$ git diff --stat HEAD^3
fatal: ambiguous argument 'HEAD^3': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
zhangshuli@zhangshuli-MS-7817:~/myGit$

git diff --stat number:用来查看 版本的详细差异(包括具体更改的文件)

git blame 文件名:查看对这个文件作出更改的历史记录

zhangshuli@zhangshuli-MS-7817:~/myGit$ git blame aaa.txt
f73968df (zhangshuli 2015-02-13 13:24:15 +0000 1) my second commit
e2e09c48 (zhangshuli 2015-02-27 09:50:58 +0000 2) add son
b7b310d2 (zhangshuli 2015-02-28 14:25:11 +0000 3) cherry-pick
f73968df (zhangshuli 2015-02-13 13:24:15 +0000 4) 
zhangshuli@zhangshuli-MS-7817:~/myGit$

当然,它也可以添加参数,如

git blame -L number1 ,number2 filename

zhangshuli@zhangshuli-MS-7817:~/myGit$ git blame -L 1,2 aaa.txt
f73968df (zhangshuli 2015-02-13 13:24:15 +0000 1) my second commit
e2e09c48 (zhangshuli 2015-02-27 09:50:58 +0000 2) add son
zhangshuli@zhangshuli-MS-7817:~/myGit$

 

转载于:https://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_zj_150228163.html

你可能感兴趣的:(git,ui)