> README.md git commit -a -m"com-6ren">
gpt4 book ai didi

git - 如何显示本地分支历史?

转载 作者:太空狗 更新时间:2023-10-29 12:59:59 26 4
gpt4 key购买 nike

我是 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

然后有人克隆了这个repo,如何显示分支历史?

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

最佳答案

您走在正确的轨道上。尝试使用:

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

如果你有能力使用 GUI 和 git,通常强烈推荐 gitk 来做这种事情。这是一个 intro .

关于git - 如何显示本地分支历史?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14889017/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com