分布式版本控制系统 Git | 三

分布式版本控制系统 Git | 三


查看提交日志


多次提交版本更新,当想回顾提交历史时。可以使用 git log 命令查看提交日志。

$ git log
commit dd6c67d9f27fa3238c9ca9b74c01dd84e355a4fd (HEAD -> master)
Author: 大梦三千秋 <[email protected]>
Date:   Mon Feb 3 20:16:52 2020 +0800

    Fix issue 007

commit c4366e8566ae7d92b61f23613da28b1929b15feb
Author: 大梦三千秋 <[email protected]>
Date:   Mon Feb 3 19:45:22 2020 +0800

    New file and change something

commit 9c3df1874694c55685c2823c62a03f7d85633fdb
Author: 大梦三千秋 <[email protected]>
Date:   Mon Feb 3 18:40:27 2020 +0800

    Create file about_git

commit 6c291327f97b559f13c94f34ea23ffdb32af52c5
Author: 大梦三千秋 <[email protected]>
Date:   Mon Feb 3 18:37:26 2020 +0800

    delelte README

git log 命令显示的是从最近到最远的提交日志。

git log 还有选项可以选择,简单介绍几个常用的选项。

例如,-p 选项:

$ git log -p -2
commit 71b1806ca672f73ca97e745bb44ce0e99fa04c85 (HEAD -> master)
Author: 大梦三千秋 <[email protected]>
Date:   Tue Feb 4 20:41:55 2020 +0800

    Add test line

diff --git a/readme.txt b/readme.txt
index a68a8b2..c390466 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,3 +1,4 @@
 Add something here

 Change something here
+# test line

commit dd6c67d9f27fa3238c9ca9b74c01dd84e355a4fd
Author: 大梦三千秋 <[email protected]>
Date:   Mon Feb 3 20:16:52 2020 +0800

    Fix issue 007

diff --git a/about_git.txt b/about_git.txt

选项 -p 的作用是,按补丁格式显示每个提交引入的差异。-2 选项表示仅显示最近的两次提交。

这个选项能够快速浏览协同者提交的 commit 带来的变化。

git log 还提供一个 --stat 选项,附带提交的简略统计信息:

$ git log --stat
commit 71b1806ca672f73ca97e745bb44ce0e99fa04c85 (HEAD -> master)
Author: 大梦三千秋 <[email protected]>
Date:   Tue Feb 4 20:41:55 2020 +0800

    Add test line

 readme.txt | 1 +
 1 file changed, 1 insertion(+)

commit dd6c67d9f27fa3238c9ca9b74c01dd84e355a4fd
Author: 大梦三千秋 <[email protected]>
Date:   Mon Feb 3 20:16:52 2020 +0800

    Fix issue 007

 about_git.txt | 3 ++-
 readme.txt    | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

commit c4366e8566ae7d92b61f23613da28b1929b15feb
Author: 大梦三千秋 <[email protected]>
Date:   Mon Feb 3 19:45:22 2020 +0800

--stat 这个选项能够查看每次提交修改过的文件,有多少被修改被修改的文件哪行发生了变化,同时在最后有个总结。

git log 默认输出的信息比较多,--pretty 选项搭配不同的格式能够展示不同形式的提交历史。

--pretty 提供的子选项中,oneline 能够大量缩减输出的信息,只显示关键的部分。

$ git log --pretty=oneline
71b1806ca672f73ca97e745bb44ce0e99fa04c85 (HEAD -> master) Add test line
dd6c67d9f27fa3238c9ca9b74c01dd84e355a4fd Fix issue 007
...

还有一些 shortmediumfull 等选项能够搭配使用,这些选项的使用所展示的格式基本一致,但是显示的内容信息详细程度不一。

还有一个 format 选项,非常特殊,能够自定义输出的格式。对后期的提取分析有很大的帮助:

$ git log --pretty=format:"%h - %an, %ar : %s"
71b1806 - 大梦三千秋, 28 minutes ago : Add test line
dd6c67d - 大梦三千秋, 25 hours ago : Fix issue 007
c4366e8 - 大梦三千秋, 25 hours ago : New file and change something
9c3df18 - 大梦三千秋, 26 hours ago : Create file about_git
6c29132 - 大梦三千秋, 27 hours ago : delelte README
956d16c - 大梦三千秋, 2 days ago : Wrote file README

上面使用的占位符具体的意义如下:

占位符 意义
%h 提交的简写哈希值
%an 作者名称
%ar 作者修改时间,按照多久之前的形式展示
%s 提交的说明

具体详细的信息可以查看官方文档 https://git-scm.com/docs/git-log#_pretty_formats 进行了解。

还有一个选项能够跟 oneline 或者 format 结合使用,就是 --graph。这个选项能够以图形的形式,在日志左侧形象展示分支以及合并的历史:

$ git log --pretty=oneline --graph
*   102a4a4f950cffae0acfb53a634012182fb8e8a1 (HEAD -> master) Fix conflict
|\
| * 04702642dbfc9b5601b69e55c8ac38918441e9d2 (dev) Add test line by dev
* | d4a2555ab7fdd1e2b3d7b768d217ab70797162a1 Add test line
|/
* ae23d790611db0a0d9360cb55c700891a9e94bf9 Create file and add newline by branch dev
* 576349c0e843bce799da5845c67a87a817dd0096 Create file DEV2
...

以上就是简单介绍 git log 命令支持的一些选项。其他未涉及的选项,可通过下方的链接进行更详细的了解。

https://git-scm.com/docs/git-log#_commit_formatting


以上就是本篇的主要内容


未完待续

发布了82 篇原创文章 · 获赞 43 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_45642918/article/details/104175895