GIT查看历史版本

使用Git工具非常容易的查看历史版本信息,并且可以任意穿梭多个版本,就像坐着时光机在可以回到以前任意的版本。

git log

查看历史版本信息非常简单,只需要使用git log命令即可

# git log
commit 34b134a45214cfbf319f4c2f3b6519a43a56ec8f
Author: gwx <704835519@qq.com>
Date:   Wed Jun 17 07:52:16 2020 +0800

  change config file

commit 33a9c75ef8f38df87079d91d51fe4076f85c6a44
Author: gwx <704835519@qq.com>
Date:   Wed Jun 17 07:51:36 2020 +0800

  add config file

commit 31402145bd40963c2e715f442fa0d16e3236f22d
Author: gwx <704835519@qq.com>
Date:   Wed Jun 17 07:50:16 2020 +0800

  change index.php file

commit 66314b15a6cb6e52c7d01996504f30c114bb0cd9
Author: gwx <704835519@qq.com>
Date:   Wed Jun 17 07:49:45 2020 +0800

  add index.php file

commit cba40afe3f7d0a4d80a89c8ad601d78a03253379
Author: gwx <704835519@qq.com>
Date:   Wed Jun 17 07:49:00 2020 +0800

  first commit.add README.md file

-p选项

使用-p选项可以查看版本间的差异,它是一个非常常用的选项。

-number

如想指定只查看几个最新的版本信息,就可以使用-number,如

git log -2
commit 34b134a45214cfbf319f4c2f3b6519a43a56ec8f
Author: gwx <704835519@qq.com>
Date:   Wed Jun 17 07:52:16 2020 +0800

  change config file

commit 33a9c75ef8f38df87079d91d51fe4076f85c6a44
Author: gwx <704835519@qq.com>
Date:   Wed Jun 17 07:51:36 2020 +0800

  add config file
# git log -p -1
commit 34b134a45214cfbf319f4c2f3b6519a43a56ec8f
Author: gwx <704835519@qq.com>
Date:   Wed Jun 17 07:52:16 2020 +0800

  change config file

diff --git a/config.php b/config.php
index f5dfecb..918f725 100644
--- a/config.php
+++ b/config.php
@@ -1,5 +1,6 @@
<?php

return [
-   'debug' => true
+   'debug' => true,
+   '404' => '404.html'
];

–stat

比如你想看到每 次提交的简略统计信息,可以使用 –stat 选项:

–pretty

$ git log --pretty=format:"%h %s" --graph
* 2d3acf9 ignore errors from SIGCHLD on trap
* 5e3ee11 Merge branch 'master' of git://github.com/dustin/grit
|\
| * 420eac9 Added a method for getting the current branch.
* | 30e367c timeout code and tests
* | 5a09431 add timeout protection to grit
* | e1193f8 support for heads with slashes in them
|/
* d6016bc require time for xmlschema
* 11d191e Merge branch 'defunkt' into local