1、git show 介绍

git show 可以用于显示提交日志的相关信息。它与 git log 的区别在于,git show 侧重于显示版本差异,输出每个commit具体修改的内容,而 git log 则侧重于显示版本的提交历史,文末有更多关于两者的介绍。我们首先来了解 git show 的基本用法吧。

2、git show 默认显示

git show 默认显示的是 HEAD,如下所示:

$ git show
commit 33edda5b930d5a366e5d5913cb64e961c6800743
Author: Tim <xxx@mail.com>
Date:   Tue Jun 25 17:53:28 2022 +0800

    modify some code

3、git show 查看某一提交的信息

git show 默认显示的是 HEAD,如想显示某个提交信息,那么在 git show 后带上某个提交的 commitId 值即可。如下所示:

$ git show ff3234f

4、git show 查看某次 commit 中具体某个文件的修改

$ git show commitId fileName

5、git show 格式化

git show --pretty[=<format>]|--format=<format>

注意:两者是等价的,git show --pretty=format:short 与 git show --format=short是等价的。

5.1、oneline 格式,以一行的格式输出提交日志,包括完整的hash值和提交备注。

$ git show --format=oneline
45a80aee40c64ad2fc7590e51975b608c09b4796 modify some code

5.2、short 格式,以短格式输出提交日志,包括hash值、作者、提交备注

$ git show --format=short
commit 45a80aee40c64ad2fc7590e51975b608c09b4796
Author: Tim <xxx@mail.com>

    modify some code

5.3、medium 格式,git show 默认以 medium 格式显示

$ git show --pretty=medium
commit 45a80aee40c64ad2fc7590e51975b608c09b4796
Author: Tim <xxx@mail.com>
Date:   Sun Nov 17 11:58:46 2020 +0800

    modify some code

5.4、full 格式,以全格式输出提交日志

$ git show --format=full
commit 45a80aee40c64ad2fc7590e51975b608c09b4796
Author: Tim <xxx@mail.com>
Commit: Tim <xxx@mail.com>

    modify some code

5.5、fuller 格式,比满格式更详细的输出提交日志

$ git show --format=fuller      
commit 45a80aee40c64ad2fc7590e51975b608c09b4796
Author:     Tim <xxx@mail.com>
AuthorDate: Sun Nov 17 11:58:46 2020 +0800
Commit:     Tim <xxx@mail.com>
CommitDate: Sun Nov 17 11:58:46 2020 +0800

    modify some code

5.6、email 格式,以email格式输出提交日志

$ git show --format=email          
commit 45a80aee40c64ad2fc7590e51975b608c09b4796
author: Tim <xxx@mail.com>
Date: Sun, 17 Nov 2020 11:58:46 +0800

    modify some code

5.7、raw 格式,以原始格式输出提交日志

$ git show --format=raw
commit 45a80aee40c64ad2fc7590e51975b608c09b4796
tree b3f72990611d77de8d0e05dff8db8e3b6b963cdf
parent 70a5ce6091aa59d5e3909af117340805214f10ee
author Tim <xxx@mail.com> 1473963126 +0800
committer Tim <xxx@mail.com> 1473963126 +0800

6、git show 命令 与 git log 命令的关系

git show命令同git log -p输出类似,只不过它只显示一个commit的内容,如果不指定commit hash,它默认输出HEAD指向commit的内容。

备注git log -p:控制输出每个commit具体修改的内容,输出的形式以diff的形式给出。

标签: none

[网站公告]-[2024年兼职介绍]


添加新评论