天天看點

Git基礎入門(四)Git曆史記錄管理

git clone https://github.com/schacon/simplegit-progit mytest            #擷取測試項目

cd  mytest

git log                                                      #檢視Git倉庫的日志資訊

    commit ca82a6dff817ec66f44342007202690a93763949

    Author: Scott Chacon <[email protected]>

    Date:   Mon Mar 17 21:52:11 2008 -0700

        changed the verison number

    commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7

    Date:   Sat Mar 15 16:40:33 2008 -0700

        removed unnecessary test code

    commit a11bef06a3f659402fe7563abf99ad00de2209e6

    Date:   Sat Mar 15 10:31:28 2008 -0700

        first commit

git log會按送出時間列出所有的更新,列出每個送出的校驗和、作者的名字和電子郵件位址、送出時間以及送出說明

git log有許多選項可以幫助搜尋你所要找的資訊,接下來我們介紹些最常用的

-p:顯示每次送出的内容差異

-N:顯示最近N次送出

git log -p -1

    diff --git a/Rakefile b/Rakefile

    index a874b73..8f94139 100644

    --- a/Rakefile

    +++ b/Rakefile

    @@ -5,7 +5,7 @@ require 'rake/gempackagetask'

     spec = Gem::Specification.new do |s|

         s.platform  =   Gem::Platform::RUBY

         s.name      =   "simplegit"

    -    s.version   =   "0.1.0"

    +    s.version   =   "0.1.1"

         s.author    =   "Scott Chacon"

         s.email     =   "[email protected]"

         s.summary   =   "A simple gem for using Git in Ruby code."

--stat:顯示每次送出簡略的統計資訊

git log --stat -1

     Rakefile | 2 +-

     1 file changed, 1 insertion(+), 1 deletion(-)

--pretty=<format>:指定使用不同于預設格式的方式展示送出曆史

    format:

        oneline将每個送出放在一行顯示,檢視的送出數很大時非常很有用

        full:檢視作者和送出者(修改者)

        fuller:輸出比full更詳細的資訊(送出者)

git log --pretty=oneline

    ca82a6dff817ec66f44342007202690a93763949 changed the verison number

    085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 removed unnecessary test code

    a11bef06a3f659402fe7563abf99ad00de2209e6 first commit

git log --pretty=full  -1

    Commit: Scott Chacon <[email protected]>

git log --pretty=fuller   -1

    Author:     Scott Chacon <[email protected]>

    AuthorDate: Mon Mar 17 21:52:11 2008 -0700

    Commit:     Scott Chacon <[email protected]>

    CommitDate: Fri Apr 17 21:56:31 2009 -0700

git log --pretty=format                 #定制要顯示的記錄格式

git log --pretty=format:"%h - %an, %ar : %s"

    ca82a6d - Scott Chacon, 10 years ago : changed the verison number

    085bb3b - Scott Chacon, 10 years ago : removed unnecessary test code

    a11bef0 - Scott Chacon, 10 years ago : first commit

選項         說明

%H          送出對象的完整哈希字串

%h          送出對象的簡短哈希字串

%T          樹對象的完整哈希字串

%t          樹對象的簡短哈希字串

%P          父對象的完整哈希字串

%p          父對象的簡短哈希字串

%an         作者的名字

%ae         作者的電子郵件位址

%ad         作者修訂日期(可以用--date=選項定制格式)

%ar         作者修訂日期,按多久以前的方式顯示

%cn         送出者的名字

%ce         送出者的電子郵件位址

%cd         送出日期

%cr         送出日期,按多久以前的方式顯示

%s          送出說明

當oneline或format與另一個log選項--graph結合使用時,這個選項添加了一些ASCII字元串來形象地展示你的分支、合并曆史

git log --pretty=oneline --graph 

    * ca82a6dff817ec66f44342007202690a93763949 changed the verison number

    * 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 removed unnecessary test code

    * a11bef06a3f659402fe7563abf99ad00de2209e6 first commit

git log <PATH>          #隻顯示指定路徑或檔案的曆史資訊

git log README

git log的常用選項

選項                 說明

-p                  按更新檔格式顯示每個更新之間的差異

-N                  N代表一個數字,表示顯示前N條資訊

--stat              顯示每次更新的檔案修改統計資訊

--shortstat         隻顯示--stat中最後的行數修改添加移除統計

--name-only         僅在送出資訊後顯示已修改的檔案清單

--name-status       顯示新增、修改、删除的檔案清單

--abbrev-commit     僅顯示校驗和的前幾個字元,而非所有的 40 個字元

--relative-date     使用較短的相對時間顯示

--graph             顯示ASCII圖形表示的分支合并曆史

--pretty            使用其他格式顯示曆史送出資訊。可用的選項包括oneline,full,fuller和format(後跟指定格式)

--since             顯示指定時間之後的送出。

--until             顯示指定時間之前的送出。

--author            顯示指定作者相關的送出。

--committer         顯示指定送出者相關的送出。

--grep              顯示含指定關鍵字的送出

-S                  顯示添加或移除了某個關鍵字的送出

本文轉自  紅塵世間  51CTO部落格,原文連結:http://blog.51cto.com/hongchen99/1976337