git查看日志
git log -n
顯示前N條記錄
git log -3
退出log命令
直接輸入: q
git log --stat -n
顯示提交的文件的簡要的修改統計
$ git log --stat -2
commit d0b9a20fac8abc7517c5a04c0fbb1d488f309bf5
Author: BeginMan <pythonsuper@gmail.com>
Date: Sat Mar 1 23:26:43 2014 +0800
ok
_posts/2014-02-27-Customizing-Git.md | 5 +++++
1 file changed, 5 insertions(+)
commit 8c186cd71492b7a3eae6df7de880b99efa0f87cf
Author: BeginMan <pythonsuper@gmail.com>
Date: Sat Mar 1 23:26:10 2014 +0800
mi
_posts/2014-02-27-Customizing-Git.md | 56 +++++++++++++++++++++++++++++++++++-
1 file changed, 55 insertions(+), 1 deletion(-)
git log -p -n
顯示文件的詳細改動
git log --graph
簡單的圖形顯示分支情況
git log --pretty=format:" "
控制顯示的記錄格式,常用的格式占位符寫法及其代表的意義如下:
選項 說明
%H 提交對象(commit)的完整哈希字串
%h 提交對象的簡短哈希字串
%T 樹對象(tree)的完整哈希字串
%t 樹對象的簡短哈希字串
%P 父對象(parent)的完整哈希字串
%p 父對象的簡短哈希字串
%an 作者(author)的名字
%ae 作者的電子郵件地址
%ad 作者修訂日期(可以用 -date= 選項定制格式)
%ar 作者修訂日期,按多久以前的方式顯示
%cn 提交者(committer)的名字
%ce 提交者的電子郵件地址
%cd 提交日期
%cr 提交日期,按多久以前的方式顯示
%s 提交說明
如下操作:
$ git log --pretty=format:"%h -%an,%ar : %s" -3
d0b9a20 -BeginMan,24 hours ago : ok
8c186cd -BeginMan,24 hours ago : mi
b2a3100 -BeginMan,24 hours ago : what?
顯示了前3條的信息,簡單的哈希值,作者,提交時間,提交說明。
個人感覺這個命令挺好的,為了方面使用,還是做個別名吧:
$ git config alias.logs "log --pretty=format:'%h -%an,%ar:%s'"
$ git config alias.logs
log --pretty=format:'%h -%an,%ar:%s'
$ git logs
git log --pretty=oneline
一行顯示,只顯示哈希值和提交說明。
git log --pretty=oneline [path]
顯示指定path(目錄或文件)下的提交
指定日期、關鍵字、作者
如兩天前的提交歷史:git log --since=2.days
如指定作者為"BeginMan"的所有提交:$ git log --author="xxxx"
如指定關鍵字為“init”的所有提交:$ git log --grep=init
如指定提交者為"Jack"的所有提交:$ git log --committer=Jack
注意作者與提交者的關系:作者是程序的修改者,提交者是代碼提交人。
如指定2天前,作者為“BeginMan”的提交含有關鍵字'init'的前2條記錄:$ git log --since=2.days --author=BeginMan --grep=init -2
上面選項后面的參數可以帶單雙引號
使用說明如下:
選項 說明
-(n) 僅顯示最近的 n 條提交
--since, --after 僅顯示指定時間之后的提交。
--until, --before 僅顯示指定時間之前的提交。
--author 僅顯示指定作者相關的提交。
--committer 僅顯示指定提交者相關的提交。
git log 命令支持的選項
-p 按補丁格式顯示每個更新之間的差異。
--stat 顯示每次更新的文件修改統計信息。
--shortstat 只顯示 --stat 中最后的行數修改添加移除統計。
--name-only 僅在提交信息后顯示已修改的文件清單。
--name-status 顯示新增、修改、刪除的文件清單。
--abbrev-commit 僅顯示 SHA-1 的前幾個字符,而非所有的 40 個字符。
--relative-date 使用較短的相對時間顯示(比如,“2 weeks ago”)。
--graph 顯示 ASCII 圖形表示的分支合並歷史。
--pretty 使用其他格式顯示歷史提交信息。可用的選項包括 oneline,short,full,fuller 和 format(后跟指定格式)。
顯示幫助
git log --help