.net mvc做網(wǎng)站一鍵優(yōu)化清理
文章目錄
- 1. 查詢 git log 的文檔
- 2. 不帶任何參數(shù): `git log` 啥意思?
- 3. `git log` 最主要功能是什么?
- 4. `git log <commit1>..<commit2>` 什么意思
- 5. 查看最近n次commit
- 6. References
1. 查詢 git log 的文檔
git help log --web
市面上針對(duì) git log
的 options
講解的文章很多,對(duì)于 <revision-range>
講解的很少,白魚(yú)在這篇帶你游覽 git log <revision-range>
的用法。
2. 不帶任何參數(shù): git log
啥意思?
前一節(jié)知道了 git 完整用法
git log [<options>] [<revision-range>] [[--] <path>…]
因此,當(dāng)不帶任何參數(shù):
git log
意味著:
<options>
為空<revision-range>
為默認(rèn)范圍<path>
沒(méi)有指定
那么默認(rèn)的 <revision-range>
是什么?答案是 HEAD
:
也就是說(shuō):git log
等價(jià)于 git log HEAD
. HEAD
的含義我們先前有提過(guò),它表示“當(dāng)前分支”, 或者說(shuō)當(dāng)前分支的最新節(jié)點(diǎn)。因此 git log
也就是 git log HEAD
意思是:從當(dāng)前分支最新節(jié)點(diǎn) HEAD
往前回溯,所有能被回溯的節(jié)點(diǎn),都列出來(lái)。懂了嗎?
git log
等價(jià)于 git log HEAD
, 意思是列出當(dāng)前分支所有 commit 節(jié)點(diǎn)。
3. git log
最主要功能是什么?
我們來(lái)看 git log
的 description 第一段的解釋:
Shows the commit logs.
List commits that are reachable by following the parent links from the given commit(s), but exclude commits that are reachable from the one(s) given with a ^ in front of them. The output is given in reverse chronological order by default.
You can think of this as a set operation. Commits reachable from any of the commits given on the command line form a set, and then commits reachable from any of the ones given with ^ in front are subtracted from that set. The remaining commits are what comes out in the command’s output. Various other options and paths parameters can be used to further limit the result.
說(shuō)的很直白了:git log
列出給定的 commit 的所有可回溯的節(jié)點(diǎn),并且略掉 ^
開(kāi)頭的節(jié)點(diǎn)及其所有可回溯節(jié)點(diǎn)。
因此:
git log foo bar ^baz
意思是列出 foo
的所有可回溯節(jié)點(diǎn)、bar
的所有可回溯節(jié)點(diǎn)、 但是會(huì)去除 baz
及其所有可回溯節(jié)點(diǎn)。
換言之, git log
命令最主要的功能,是根據(jù)給出的若干 commit, 每個(gè)commit對(duì)應(yīng)一個(gè)集合,執(zhí)行集合的合并以及減法操作,最終得到一個(gè) commit 集合。
如果還不明白,再解釋一下 git log foo bar ^baz
:
foo
: 得到以foo
為末尾節(jié)點(diǎn)的 commit 集合foo-set
bar
: 得到以bar
為末尾節(jié)點(diǎn)的 commit 集合bar-set
^baz
: 得到以baz
為末尾節(jié)點(diǎn)的 commit 集合baz-set
- 最終計(jì)算:
foo-set
+bar-set
-baz-set
4. git log <commit1>..<commit2>
什么意思
A special notation “…” can be used as a short-hand for “^ ”. For example, either of the following may be used interchangeably:
$ git log origin..HEAD
$ git log HEAD ^origin
也就是說(shuō), git log <commit1>..<commit2>
是 git log ^<commit1> <commit2>
的簡(jiǎn)寫(xiě), 意思是從 commit2 回溯得到的 commit 集合, 減去 commit1 及其回溯得到的集合。
實(shí)際上 <commit1>
和 <commit2>
也可以換成分支的名字, 例如 git log main..feature
表示的是, feature
分支特有的、 main
分支沒(méi)有的 commit:
再舉一個(gè)極端例子:如果只想查看某個(gè) git repo 的第一個(gè)commit: 首先用 gitk 或 git log 等任意工具查詢得到第一個(gè) commit 的 sha-1, 然后執(zhí)行
git log <first-commit-sha>
或
gitk log <first-commit-sha>
從而只查看第一個(gè)commit
在這里插入圖片描述
5. 查看最近n次commit
很多人的直覺(jué)是:
git log -n
但其實(shí)基于上一節(jié)的結(jié)論,很容易想到另一種表示:
git log HEAD ^HEAD~n
6. References
- https://git-scm.com/docs/git-log
- https://www.atlassian.com/git/tutorials/git-log