Git 基礎 - 查看提交歷史

git log 有許多選項能夠幫助你搜尋你所要找的提交, 接下來咱們介紹些最經常使用的。html

一個經常使用的選項是 -p,用來顯示每次提交的內容差別。 你也能夠加上 -2 來僅顯示最近兩次提交:git

$ git log -p -2  ##貌似有時候後面-2參數不用寫,或者不起效果
 

commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Mon Mar 17 21:52:11 2008 -0700

    changed the version number

diff --git a/Rakefile b/Rakefile
index a874b73..8f94139 100644
--- a/Rakefile
+++ b/Rakefile

該選項除了顯示基本信息以外,還在附帶了每次 commit 的變化。 當進行代碼審查,或者快速瀏覽某個搭檔提交的 commit 所帶來的變化的時候,這個參數就很是有用了。 你也能夠爲 git log 附帶一系列的總結性選項。 好比說,若是你想看到每次提交的簡略的統計信息,你能夠使用 --stat 選項:spa

$ git log --stat

commit ca82a6dff817ec66f44342007202690a93763949
Author: Scott Chacon <schacon@gee-mail.com>
Date:   Mon Mar 17 21:52:11 2008 -0700

    changed the version number

 Rakefile |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

$ git log --graph --oneline --decorate --all
 

圖形化比較顯示所有不一樣的commit code

而後你能夠根據狀況查看不一樣的兩次commit的區別htm

git diff 4ac0a6733 4ac0a6733

 

git log --follow file   ##顯示文件更新歷史

--followblog

Continue listing the history of a file beyond renames (works only for a single file).ip

關於git diff 輸出結果分析能夠參考博文:ci

http://www.ruanyifeng.com/blog/2012/08/how_to_read_diff.htmlrem

git log 顯示各個branch 提交歷史

ll changes made by commits in the current branch but that are not in <upstream> are saved to a temporary area. This is the same set of commits that would be shown by git log <upstream>..HEAD; or by git log 'fork_point'..HEAD, if --fork-point is active (see the description on --fork-point below); or by git log HEAD, if the --root option is specified.get

如上是英文說明。

其實能夠經過 

git log <upstream>..HEAD 

將不一樣的branch聯合顯示。

另外想查看一個branch的提交歷史能夠查看

git log branch-name

參考博文:

https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E9%AB%98%E7%BA%A7%E5%90%88%E5%B9%B6#_manual_remerge

https://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2

相關文章
相關標籤/搜索