Git log and got show
review a repository's history are git log and git show
Git log
git log:display information about the existing commits
默认情况下,该命令会显示仓库中每个 commit 的:
-
SHA
-
作者
-
日期
-
消息
SHA: SHA 基本上就是每次提交的 ID 号码,是由 40 个字符(0-9 和 a-f)组成的字符串,根据 Git 中的文件内容或目录结构计算而成。“SHA”是“SHA散列”的简写。
git uses the less program as its pager,
1.press either the J key or the down arrow to scroll down one line at a time.
2. to scroll up press the K key or the up arrow.
3.When the colon(冒号) changes to the word end,you’ve reached the very last commit.
4. to get out of the pager just press the Q key.
git log --oneline
$ git log --oneline
用来更改仓库信息的显示方式
此命令:
-
每行显示一个 commit
-
显示 commit 的 SHA 的前 7 个字符
-
显示 commit 的消息
q 键使终端返回命令提示符
git log --stat
显示 commit 中更改的文件以及添加或删除的行数
此命令会:
-
显示被修改的文件
-
显示添加/删除的行数
-
显示一个摘要,其中包含修改/删除的总文件数和总行数
git log -p(patch)
git can keep track of renamed files.
带注释的 git log -p 输出
我们通过上述图片快速总结下 git log -p 的输出:
- 🔵 - 正在显示的文件
- 🔶 - 文件第一版的哈希值和第二版的哈希值
通常不重要,因此可以忽略 - ❤️ - 文件的旧版本和当前版本
- 🔍 - 添加的行所在的位置以及添加了多少行
- -15,83 表示旧版本(用 - 表示)从第 15 行开始,显示了 83 行
- +15,85 表示当前版本(用 + 表示)从第 15 行开始,现在变成了 85 行…这 85 行显示在下方
- ✏️ - 在 commit 中实际进行的更改
- 用红色标示并以减号 (-) 开头的行是位于文件原始版本中,但是被 commit 删除的行
- 用绿色标示并以加号 (+) 开头的行是 commit 新加的行
git log -p -w
-w
-
–ignore-all-space
ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none. -
–ignore-blank-lines
Ignore changes whose lines are all blank.
git log --pretty
这个选项可以使用不同于默认格式的方式展示提交历史.这个选项有一些内建的子选项供你使用。 比如 oneline 会将每个提交放在一行显示,在浏览大量的提交时非常有用。 另外还有 short,full 和 fuller 选项,它们展示信息的格式基本一致,但是详尽程度不一:
$ git log --pretty=oneline
ca82a6dff817ec66f44342007202690a93763949 changed the version number
085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 removed unnecessary test
a11bef06a3f659402fe7563abf99ad00de2209e6 first commit
最有意思的是 format ,可以定制记录的显示格式。 这样的输出对后期提取分析格外有用——因为你知道输出的格式不会随着 Git 的更新而发生改变:
$ git log --pretty=format:"%h - %an, %ar : %s"
ca82a6d - Scott Chacon, 6 years ago : changed the version number
085bb3b - Scott Chacon, 6 years ago : removed unnecessary test
a11bef0 - Scott Chacon, 6 years ago : first commit
显示特定commit的详情
- 向 git log 提供你要查看的 commit 的 SHA
- 使用 git show 命令
git show:display information about the given commit
git show 命令将仅显示一个 commit。git show 命令的输出和 git log -p 命令的完全一样。
git show 可以与我们了解过的大部分其他选项一起使用:
-
–stat - 显示更改了多少文件,以及添加/删除的行数
-
-p 或 --patch - 显示默认补丁信息,但是如果使用了 --stat,将不显示补丁信息,因此传入 -p 以再次添加该信息
-
-w - 忽略空格变化