查看提交歷史
git log
命令用于查看提交歷史
$ git log
commit ca82a6dff817ec66f44342007202690a93763949
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
默認(rèn)不使用參數(shù)的話,git log
會按提交時間列出所有的更新,最近的更新在最上面。這個命令列出每個提交的 SHA-1 校驗和、作者的名字和電子郵件地址、提交時間以及提交說明。
git log
有很多選項可以幫助你搜索你要找的提交:
-
-p
用于顯示每次提交內(nèi)容的差異,git log -p -2
-
--stat
用于顯示每次提交的簡略的統(tǒng)計信息,git log -stat
-
--pretty
指定使用不同于默認(rèn)格式的方式展示提交歷史,-
git log --pretty=oneline
(在一行顯示),short
,full
,fuller
等. -
git log --pretty=format:"%h - %an, %ar : %s"
,定制要顯示的格式
-
--graph
這個選項添加了一些 ASCII字符串來形象地展示分支,合并歷史
*git log --pretty=format:"%h %s"
--graph
限制輸出長度
$git log --since=2.weeks
選項 | 說明 |
---|---|
-(n) | 僅顯示最近的 n 條提交 |
--since, --after | 僅顯示指定時間之后的提交。 |
--until , --before | 僅顯示指定時間之前的提交。 |
--author | 僅顯示指定作者相關(guān)的提交。 |
--committer | 僅顯示指定提交者相關(guān)的提交。 |
--grep | 僅顯示含指定關(guān)鍵字的提交 |
-S | 僅顯示添加或移除了某個關(guān)鍵字的提交 |
Table. 限制 git log
輸出的選項
來看一個實際的例子,如果要查看 Git 倉庫中,2008 年 10 月期間,Junio Hamano 提交的但未合并的測試文件,可以用下面的查詢命令:
$ git log --pretty="%h - %s" --author=gitster --since="2008-10-01" \
--before="2008-11-01" --no-merges -- t/
5610e3b - Fix testcase failure when extended attributes are in use
acd3b9e - Enhance hold_lock_file_for_{update,append}() API
f563754 - demonstrate breakage of detached checkout with symbolic link HEAD
d1a43f2 - reset --hard/read-tree --reset -u: remove unmerged new paths
51a94af - Fix "checkout --track -b newbranch" on detached HEAD
b0ad11e - pull: allow "git pull origin $something:$current_branch" into an unborn branch