码迷,mamicode.com
首页 > 其他好文 > 详细

worktools-git 工具的使用总结(5)

时间:2015-02-28 18:06:42      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:

1.查看历史记录git log

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

commit b7b310d220628530d1feb9e8046ccb59039d59f2
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Sat Feb 28 14:25:11 2015 +0000

    cherry-pick

commit ac63f3e801e4022b34ba14ed9d1ae75b022ff067
Merge: 02906a1 618011f
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Sat Feb 28 14:18:04 2015 +0000

    Merge branch third into parent

commit 02906a15dc15be5fefd5e41dcd3977bb2f762cff
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Sat Feb 28 14:10:45 2015 +0000

    yahe

commit 618011fc23e6fe8108e830e2812a298ad217d0cb
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Sat Feb 28 14:08:45 2015 +0000

    commit ddd

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

commit b7b310d220628530d1feb9e8046ccb59039d59f2
Author: zhangshuli <zhangshuli@vanzotec.cn>
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 <zhangshuli@vanzotec.cn>
Date:   Sat Feb 28 14:18:04 2015 +0000

    Merge branch third into parent

commit 02906a15dc15be5fefd5e41dcd3977bb2f762cff
Author: zhangshuli <zhangshuli@vanzotec.cn>
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 <zhangshuli@vanzotec.cn>
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 <zhangshuli@vanzotec.cn>
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 <zhangshuli@vanzotec.cn>
Date:   Sat Feb 28 14:25:11 2015 +0000

    cherry-pick

commit ac63f3e801e4022b34ba14ed9d1ae75b022ff067
Merge: 02906a1 618011f
Author: zhangshuli <zhangshuli@vanzotec.cn>
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 <zhangshuli@vanzotec.cn>
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 <zhangshuli@vanzotec.cn>
Date:   Sat Feb 28 14:25:11 2015 +0000

    cherry-pick

commit ac63f3e801e4022b34ba14ed9d1ae75b022ff067
Merge: 02906a1 618011f
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Sat Feb 28 14:18:04 2015 +0000

    Merge branch third into parent

commit 02906a15dc15be5fefd5e41dcd3977bb2f762cff
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Sat Feb 28 14:10:45 2015 +0000

    yahe

commit 618011fc23e6fe8108e830e2812a298ad217d0cb
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Sat Feb 28 14:08:45 2015 +0000

    commit ddd

commit 6a74382c9c481515cd70136ce3212ace7aa1c50e
Author: zhangshuli <zhangshuli@vanzotec.cn>
Date:   Sat Feb 28 14:08:24 2015 +0000

    commit ccc.txt

commit 2a30fca479f7a953d9348067670f292780d49515
Author: zhangshuli <zhangshuli@vanzotec.cn>
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$ 

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

^:这个表示的是回溯,如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$

 

worktools-git 工具的使用总结(5)

标签:

原文地址:http://www.cnblogs.com/zhangshuli-1989/p/zhangshuli_zj_150228163.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!