查看提交歷史
git log
查看提交紀錄
$ git log
commit ca82a6dff817ec66f44342007202690a93763949 (HEAD -> master, origin/master, origin/HEAD)
Author: Scott Chacon <schacon@gmail.com>
Date: Mon Mar 17 21:52:11 2008 -0700
changed the verison number
commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7
Author: Scott Chacon <schacon@gmail.com>
Date: Sat Mar 15 16:40:33 2008 -0700
removed unnecessary test code
commit a11bef06a3f659402fe7563abf99ad00de2209e6
Author: Scott Chacon <schacon@gmail.com>
Date: Sat Mar 15 10:31:28 2008 -0700
first commit
默認不用任何參數(shù)的話,git log
會按提交時間列出所有的更新轻猖,最近的更新排在最上面。每次更新都有一個 SHA-1 校驗和、作者的名字和電子郵件地址粱哼、提交時間,最后縮進一個段落顯示提交說明檩咱。
常用參數(shù)
有許多選項可以幫助搜尋的提交揭措。
-n
默認git log
顯示所有提交,
-
git log -2
顯示最后兩次提交刻蚯、 -
git log -1
顯示最后一次提交
filename
查看某個文件的提交
-
git log README
顯示README的所有提交 -
git log -2 README
顯示README最后兩次提交
-p
展開顯示每次提交的內(nèi)容差異(把修改的內(nèi)容全部打印出來)
-
git log
顯示每次提交的差異 -
git log -p -2
顯示最后兩次提交的差異 -
git log -p README
顯示README的每次提交差異
--word-diff
展示每次提交的內(nèi)容差異(單詞層面的對比)
-
git log -U2 --word-diff
顯示每次提交的單詞的差異 -
git log -p -2 --word-diff
最后兩次提交的單詞的差異
-U2
上下文打印兩行 (已修改行為基礎(chǔ)绊含,上下各兩行)
-U3
上下文打印三行
這里展示的新增加的單詞被 {+ +}
括起來,被刪除的單詞被 [- -]
括起來
--stat
顯示簡要的每個文件的增改行數(shù)統(tǒng)計炊汹,列出了修改過的文件躬充,以及其中添加和移除的行數(shù),并在最后列出所有增減行數(shù)小計
-
git log --stat
顯示每提交的每個文件的增改行數(shù)
--shortstat 不常用
只顯示 --stat 中最后的行數(shù)修改添加移除統(tǒng)計
git log --shortstat
--name-only 不常用
僅在提交信息后顯示已修改的文件清單
git log --name-only
--abbrev-commit
顯示 SHA-1 的前幾個字符,而非所有的 40 個字符
git log abbrev-commit
--pretty
使用其他格式顯示歷史提交信息充甚∫哉可用的選項包括 oneline,short伴找,full妙蔗,fuller 和 format(后跟指定格式)
-
git log --pretty=oneline
每次提交顯示在一行 -
git log --pretty=short
每次提交顯示簡短信息 (Author) -
git log --pretty=full
每次提交顯示相對多的內(nèi)容(Author/Commit) -
git log --pretty=fuller
每次提交顯示詳細內(nèi)容 (Author/AuthorDate/Commit/CommitDate) -
git log --pretty=format:"%h - %an, %ar: %s"
自定義格式顯示
format格式
選項 | 說明 |
---|---|
%H | 提交對象(commit)的完整哈希字串 |
%h | 提交對象的簡短哈希字串 |
%T | 樹對象(tree)的完整哈希字串 |
%t | 樹對象的簡短哈希字串 |
%P | 父對象(parent)的完整哈希字串 |
%p | 父對象的簡短哈希字串 |
%an | 作者(author)的名字 |
%ae | 作者的電子郵件地址 |
%ad | 作者修訂日期(可以用 -date= 選項定制格式) |
%ar | 作者修訂日期,按多久以前的方式顯示 |
%cn | 提交者(committer)的名字 |
%ce | 提交者的電子郵件地址 |
%cd | 提交日期 |
%cr | 提交日期疆瑰,按多久以前的方式顯示 |
%s | 提交說明 |
--graph
看到開頭多出一些 ASCII 字符串表示的簡單圖形眉反,形象地展示了每個提交所在的分支及其分化衍合情況
限制輸出長度
git log
還有許多非常實用的限制輸出長度的選項,也就是只輸出部分提交信息穆役。之前我們已經(jīng)看到過 -2 了寸五,它只顯示最近的兩條提交,實際上耿币,這是 -<n>
選項的寫法梳杏,其中的 n 可以是任何自然數(shù),表示僅顯示最近的若干條提交淹接。
選項 | 說明 |
---|---|
-(n) | 僅顯示最近的 n 條提交 |
--since, --after | 僅顯示指定時間之后的提交 |
--until, --before | 僅顯示指定時間之前的提交 |
--author | 僅顯示指定作者相關(guān)的提交 |
--grep | 模糊匹配提交內(nèi)容 (多次--grep 默認查詢是或) |
--all-match | 多次--grep與查詢 需要加上 --all-match |
--committer | 僅顯示指定提交者相關(guān)的提交 |
-
git log --since="2017-11-29"
顯示11月29號以后的提交(包括29號) -
git log --after="2017-11-29"
(同上) -
git log --until="2017-11-29"
顯示11月29號以前的提交(包括29號) -
git log --before="2017-11-29"
(同上) -
git log --author="yin"
顯示作者是“yin”提交的內(nèi)容 -
git log --grep="FTP"
顯示提交內(nèi)容包含F(xiàn)TP內(nèi)容的提交 -
git log --grep="update" --grep="list" --all-match
查詢提交內(nèi)容包含update且包含list的提交紀錄 -
git log --committer="yin"
顯示提交者(commit的人)的提交
$ git log --grep="update" --grep="list" --all-match
commit 2d06020a37be740273c52daabd867a3e23ccc226
Author: yin <yjd@zhuming.com>
Date: Mon Oct 9 17:10:13 2017 +0800
web update response list