我对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 <test1@adsf.com>
| Date: Fri Feb 15 14:37:43 2013 +0900
|
| commit in branch b1
|
* commit 08e80fc644fa7ebb374a601e16533a8fc3578f88
| Author: test1 <test1@adsf.com>
| Date: Fri Feb 15 14:37:04 2013 +0900
|
| commit in branch master
|
* commit 9d9649cdb409654616798d8feeb516738997e2e0
Author: test1 <test1@adsf.com>
Date: Thu Feb 14 21:33:46 2013 -0800
Initial commit
我也看到了一些这样的日志:
* commit 2f49d77afe0708037eab1de3d216484d01f1c190
| Author: ericz <really.ez@gmail.com>
| Date: Wed Feb 13 11:45:49 2013 -0800
|
| readme update
|
* commit 996214b87cce3473297ed0997ca567497271e05a
|\ Merge: a239b70 5269cd4
| | Author: ericz <really.ez@gmail.com>
| | Date: Wed Feb 13 11:45:23 2013 -0800
| |
| | Merge branch 'master' of github.com:peers/peerjs
| |
| * commit 5269cd455f1522e88ab5a15228effe11665e6a89
| | Author: Eric Zhang <really.ez@gmail.com>
| | Date: Wed Feb 13 09:47:05 2013 -0800
| |
| | Update README.md
| |
* | commit a239b706f294c469a5c6542ce7e6f5e60417445a
| | Author: ericz <really.ez@gmail.com>
| | Date: Wed Feb 13 11:45:09 2013 -0800
| |
| | new exmales
| |
* | commit 0ce560d093637b3a17c7b5f1ab1de3f9c00bb888
|/ Author: ericz <really.ez@gmail.com>
| 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 :(得分:8)
你走在正确的轨道上。尝试使用:
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。