Git日志操作

      1.查看日志

$ git log
commit 4484696d518ce0938e46ed7b346b3219f5428cfd
Author: yuanchengbo <yuanchengbo@csair.com>
Date:   Thu Oct 26 20:44:02 2017 +0800

    modified 111 to 222

commit e66ad601e30d8be6a3986c4788d4bea0c1d7e5a7
Author: yuanchengbo <yuanchengbo@csair.com>
Date:   Thu Oct 26 20:40:19 2017 +0800

    add 111

commit 4db97b2381eae5cc61fd77527ea2af53bac4725f
Author: yuanchengbo <yuanchengbo@csair.com>
Date:   Thu Oct 26 20:32:51 2017 +0800

    add dudu in 2.txt

  上面是使用了git log命令后,截取了靠前的三个log信息。

      2.使用git show查看具体的信息

$ git show 4484696
commit 4484696d518ce0938e46ed7b346b3219f5428cfd
Author: yuanchengbo <yuanchengbo@csair.com>
Date:   Thu Oct 26 20:44:02 2017 +0800

    modified 111 to 222

diff --git a/2.txt b/2.txt
index 58c9bdf..c200906 100644
--- a/2.txt
+++ b/2.txt
@@ -1 +1 @@
-111
+222

  show之后接的是commit 的id,并不需要输全,Git是会自己去匹配的。

       3.使用-p查看log具体的信息

$ git log -p
commit 4484696d518ce0938e46ed7b346b3219f5428cfd
Author: yuanchengbo <yuanchengbo@csair.com>
Date:   Thu Oct 26 20:44:02 2017 +0800

    modified 111 to 222

diff --git a/2.txt b/2.txt
index 58c9bdf..c200906 100644
--- a/2.txt
+++ b/2.txt
@@ -1 +1 @@
-111
+222

commit e66ad601e30d8be6a3986c4788d4bea0c1d7e5a7
Author: yuanchengbo <yuanchengbo@csair.com>
Date:   Thu Oct 26 20:40:19 2017 +0800

    add 111

diff --git a/2.txt b/2.txt
index 6bf0568..58c9bdf 100644
--- a/2.txt
+++ b/2.txt
@@ -1 +1 @@
-dudu is the best
+111

  使用-p属性显示的是每条log的具体信息了。

      4.使用-n查看前n条信息

      加入log太多,只想看最近的几条log。可以使用-n来限定

$ git log -p -1
commit 4484696d518ce0938e46ed7b346b3219f5428cfd
Author: yuanchengbo <yuanchengbo@csair.com>
Date:   Thu Oct 26 20:44:02 2017 +0800

    modified 111 to 222

diff --git a/2.txt b/2.txt
index 58c9bdf..c200906 100644
--- a/2.txt
+++ b/2.txt
@@ -1 +1 @@
-111
+222

  这里使用-p -1现在最近的一条的具体信息。

     5.查看粗略的信息

$ git log --stat -1
commit 4484696d518ce0938e46ed7b346b3219f5428cfd
Author: yuanchengbo <yuanchengbo@csair.com>
Date:   Thu Oct 26 20:44:02 2017 +0800

    modified 111 to 222

 2.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

  你觉得-p显示的信息太复杂,只想要简单的信息,可以使用--stat属性,同样也可以使用-n来限制log数量。

原文地址:https://www.cnblogs.com/bocurry/p/7761827.html