2013-02-15 102 views
4

我對git很陌生,我想知道如何跟蹤分支歷史?如何顯示本地分支歷史記錄?

例如:

echo "update README in branch master" >> README.md 
git commit -a -m"commit in branch master" 
git checkout -b b1 
echo "update README in branch b1" >> README.md 
git commit -a -m"commit in branch b1" 
git checkout master 
git merge b1 
git push 

然後有人克隆此回購,如何顯示分支歷史?

git log --graph 

* commit 4162ecc962aa020ec6294312e4f8eed63ca152d1 
| Author: test1 <[email protected]> 
| Date: Fri Feb 15 14:37:43 2013 +0900 
| 
|  commit in branch b1 
| 
* commit 08e80fc644fa7ebb374a601e16533a8fc3578f88 
| Author: test1 <[email protected]> 
| Date: Fri Feb 15 14:37:04 2013 +0900 
| 
|  commit in branch master 
| 
* commit 9d9649cdb409654616798d8feeb516738997e2e0 
    Author: test1 <[email protected]> 
    Date: Thu Feb 14 21:33:46 2013 -0800 

      Initial commit 

我也看到了一些這樣的日誌:

* commit 2f49d77afe0708037eab1de3d216484d01f1c190 
| Author: ericz <[email protected]> 
| Date: Wed Feb 13 11:45:49 2013 -0800 
| 
|  readme update 
| 
* commit 996214b87cce3473297ed0997ca567497271e05a 
|\ Merge: a239b70 5269cd4 
| | Author: ericz <[email protected]> 
| | Date: Wed Feb 13 11:45:23 2013 -0800 
| | 
| |  Merge branch 'master' of github.com:peers/peerjs 
| | 
| * commit 5269cd455f1522e88ab5a15228effe11665e6a89 
| | Author: Eric Zhang <[email protected]> 
| | Date: Wed Feb 13 09:47:05 2013 -0800 
| | 
| |  Update README.md 
| | 
* | commit a239b706f294c469a5c6542ce7e6f5e60417445a 
| | Author: ericz <[email protected]> 
| | Date: Wed Feb 13 11:45:09 2013 -0800 
| | 
| |  new exmales 
| | 
* | commit 0ce560d093637b3a17c7b5f1ab1de3f9c00bb888 
|/ Author: ericz <[email protected]> 
| Date: Wed Feb 13 11:02:33 2013 -0800 
| 
|  simple chat example 

這是如何發生的?

和如何繪製圖形是這樣的:

   D---E-------F 
        / \  \ 
        B---C---G---H---I---J 
        /     \ 
        A-------K---------------L--M 
+0

你的第一個例子太簡單了,所以'git'只以快進的方式應用補丁,沒有合併提交。你可以使用'git merge --no-ff'強制'git'創建合併提交,而不是快進。 – ydroneaud 2013-02-15 13:43:50

回答

5

你在正確的軌道上。嘗試使用:

git log --graph --all --oneline 

下面是一個例子:

* e96e246 H 
| * c12759a G 
|/ 
* 547058e F 
|\ 
| * b81eb87 E 
* | 26a34db D 
| | * 47a536f C 
| | * b8fa965 B 
| |/ 
|/| 
* | cd14ec4 A 

我個人使用的.gitconfig的alais,

[alias] 
    graph = log --graph --all --date=short --pretty=format':%C(yellow)%h%Cblue%d%Creset %s %Cgreen %aN, %ad%Creset' 

這給類似的輸出,但是稍微迷死(分公司,日期,作者):

* e96e246 (HEAD, master, origin/master) H. Developer A, 2012-12-13 
| * c12759a (branch_2) G. Developer B, 2012-12-13 
|/ 
* 547058e F. Developer C, 2012-12-11 
|\ 
| * b81eb87 E. Developer A, 2012-11-28 
* | 26a34db D. Developer C, 2012-12-11 
| | * 47a536f (branch_1) C. Developer B, 2012-10-10 
| | * b8fa965 B. Developer B, 2012-10-11 
| |/ 
|/| 
* | cd14ec4 A. Developer B, 2012-10-10 

如果你有能力在git上使用GUI,通常強烈建議使用gitk來處理這種事情。這是一個intro