天天看點

檢視曆史--Git日志

git log指令可以顯示所有的送出(commit)…..

顯示更新檔(patchs):

$ git log -p

commit da9973c6f9600d90e64aac647f3ed22dfd692f70
Author: Robert Schiele <[email protected]>
Date:   Mon Aug 18 16:17:04 2008 +0200

    adapt git-cvsserver manpage to dash-free syntax

diff --git a/Documentation/git-cvsserver.txt b/Documentation/git-cvsserver.txt
index c2d3c90..785779e 100644
--- a/Documentation/git-cvsserver.txt
+++ b/Documentation/git-cvsserver.txt
@@ -11,7 +11,7 @@ SYNOPSIS
 SSH:

 [verse]
-export CVS_SERVER=git-cvsserver
+export CVS_SERVER="git cvsserver"
 'cvs' -d :ext:user@server/path/repo.git co <HEAD_name>

 pserver (/etc/inetd.conf):           

複制

## 日志統計

如果用

--stat

選項使用

git log

,它會顯示在每個送出(commit)中哪些檔案被修改了,這些檔案分别添加或删除了多少行内容。

➜  changjiashuai git:(master) git log --stat
commit adf7bdbdbe5a8d11339109cc467cac4242d1562a
Author: changjiashuai <[email protected]>
Date:   Thu Jul 10 16:04:35 2014 +0800

    --update test post

 ...13\345\257\274\345\205\245\345\210\260Android Studio.markdown" | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

commit e0239348407af7cde745994ba52761645da2e0df
Author: changjiashuai <[email protected]>
Date:   Thu Jul 10 13:48:15 2014 +0800

    --update test post

 ...74\345\205\245\345\210\260Android Studio.markdown" | 19 +++++++++++++++++++
 ...\257\274\345\205\245\345\210\260Android Studio.md" | 19 -------------------
 2 files changed, 19 insertions(+), 19 deletions(-)

commit 81020af469bb390c64e726ff9660ed9d7d8beea6
Author: changjiashuai <[email protected]>
Date:   Thu Jul 10 13:45:17 2014 +0800           

複制

格式化日志

你可以按你的要求來格式化日志輸出。

--pretty

參數可以使用若幹表現格式,如

oneline

:

➜  changjiashuai git:(master) git log --pretty=oneline
adf7bdbdbe5a8d11339109cc467cac4242d1562a --update test post
e0239348407af7cde745994ba52761645da2e0df --update test post
81020af469bb390c64e726ff9660ed9d7d8beea6 --test add post blog
e1550187da873a3545b3600da62d923c77a5effd --init my blog           

複制

或者你也可以使用

short

格式:

➜  changjiashuai git:(master) git log --pretty=short
commit adf7bdbdbe5a8d11339109cc467cac4242d1562a
Author: changjiashuai <[email protected]>

    --update test post

commit e0239348407af7cde745994ba52761645da2e0df
Author: changjiashuai <[email protected]>

    --update test post

commit 81020af469bb390c64e726ff9660ed9d7d8beea6
Author: changjiashuai <[email protected]>

    --test add post blog

commit e1550187da873a3545b3600da62d923c77a5effd
Author: changjiashuai <[email protected]>

    --init my blog           

複制

你也可用

medium

,

full

,

fuller

,

email

,

raw

。如果這些格式不完全符合你的要求,你也可以用

--pretty=format

參數(參見:git log)來建立你自己的格式。

➜  changjiashuai git:(master) git log --pretty=format:'%h was %an, %ar, message: %s'
adf7bdb was changjiashuai, 18 hours ago, message: --update test post
e023934 was changjiashuai, 21 hours ago, message: --update test post
81020af was changjiashuai, 21 hours ago, message: --test add post blog
e155018 was changjiashuai, 21 hours ago, message: --init my blog           

複制

另一個有趣的事是:你可以用

--graph

選項來可視化你的送出圖(commit graph),就像下面這樣:

➜  changjiashuai git:(master) git log --pretty=format:'%h : %s' --graph
* adf7bdb : --update test post
* e023934 : --update test post
* 81020af : --test add post blog
* e155018 : --init my blog           

複制

它會用ASCII字元來畫出一個很漂亮的送出曆史(commit history)線。

日志排序

你也可以把日志記錄按一些不同的順序來顯示。 注意:git日志從最近的送出(commit)開始,并且從這裡開始向它們父分支回溯。然而git曆史可能包括多個互不關聯的開發路線,這樣有時送出(commit)顯示出來就有點雜亂。

如果你要指定一個特定的順序,可以為git log指令添加順序參數(ordering option)。

按預設情況,送出(commits)會按逆時間(reverse chronological)順序顯示。

但是你也可以指定

--topo-order

參數,這就會讓送出(commits)按拓撲順序顯示(就是子送出在它們的父送出前顯示)。如果你用git log指令按拓撲順序來顯示git倉庫的送出日志,你會看到”開發線”(development lines)都會集合在一起。

➜  changjiashuai git:(master) git log --pretty=format:'%h : %s' --topo-order --graph
* adf7bdb : --update test post
* e023934 : --update test post
* 81020af : --test add post blog
* e155018 : --init my blog           

複制

你也可以用’–date-order’參數,這樣顯示送出日志的順序主要按送出日期來排序. 這個參數和’–topo-order’有一點像,沒有父分支會在它們的子分支前顯示,但是其它的東東還是按交時間來排序顯示。你會看到”開發線”(development lines)沒有集合一起,它們會像并行開發(parallel development)一樣跳來跳去的:

$ git log --pretty=format:'%h : %s' --date-order --graph
*   4a904d7 : Merge branch 'idx2'
|\  
* | 81a3e0d : updated packfile code to recognize index v2
| *   dfeffce : merged in bryces changes and fixed some testing issues
| |\  
| * | c615d80 : fixed a log issue
|/ /  
| * 23f4ecf : Clarify how to get a full count out of Repo#commits
| *   9d6d250 : Appropriate time-zone test fix from halorgium
| |\  
| * | decfe7b : fixed manifest and grit.rb to make correct gemspec
| * | cd27d57 : added lib/grit/commit_stats.rb to the big list o' file
| * | 823a9d9 : cleared out errors by adding in Grit::Git#run method
| * |   4eb3bf0 : resolved merge conflicts, hopefully amicably
| |\ \  
| * | | ba23640 : Fix CommitDb errors in test (was this the right fix?
| * | | 4d8873e : test_commit no longer fails if you're not in PDT
| * | | b3285ad : Use the appropriate method to find a first occurrenc
| * | | 44dda6c : more cleanly accept separate options for initializin
| * | | 839ba9f : needed to be able to ask Repo.new to work with a bar
| | * | d065e76 : empty commit to push project to runcoderun
* | | | 791ec6b : updated grit gemspec
* | | | 756a947 : including code from github updates
| | * | 3fa3284 : whitespace
| | * | d01cffd : whitespace
| * | | a0e4a3d : updated grit gemspec
| * | | 7569d0d : including code from github updates           

複制

最後,你也可以用 ‘–reverse’參數來逆向顯示所有日志。