这里主要讲分支branch , 标签tag的真实含义
1, 再看 .git的结构
chuangchuang@chuang:~/work/temp/gittest[dev*]$ tree .git/
.git/
├── branches
├── COMMIT_EDITMSG
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── index
├── info
│ └── exclude
├── logs
│ ├── HEAD
│ └── refs
│ ├── heads
│ │ ├── dev
│ │ └── master
│ └── remotes
│ └── origin
│ └── master
├── objects
│ ├── 45
│ │ └── 776d6cb67571cfe31656fb1d114e520c9e0ab2
│ ├── 68
│ │ └── d98b1781c29d1df8b4ac7b6d457bccecf9756e
│ ├── a3
│ │ └── c8effc24eeb66de97a66b073c6d62c48fbc9ed
│ ├── e4
│ │ └── 626567ec9ae5a6f3abd77af37c25a85ec4e7f1
│ ├── e6
│ │ └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391
│ ├── f1
│ │ └── 3f51556efabe074d5b255eabcdd3ec33520c55
│ ├── info
│ └── pack
└── refs
├── heads
│ ├── dev
│ └── master
├── remotes
│ └── origin
│ └── master
└── tags
2.讲讲 HEAD
HEAD代表了当前仓库的最新版本
看看里面有啥
chuangchuang@chuang:~/work/temp/gittest[dev*]$ cat .git/HEAD
ref: refs/heads/dev
可以看到,这个head指向的是一个分支dev
在看看这个refs/heads/dev中存放的是什么
chuangchuang@chuang:~/work/temp/gittest[dev*]$ cat .git/refs/heads/dev
45776d6cb67571cfe31656fb1d114e520c9e0ab2
可以看到是指向了一个commit而已
3, 讲讲tag
上面的.git目录中没有对应tag信息
3.1 新建一个tag
chuangchuang@chuang:~/work/temp/gittest[dev*]$ git tag -a v1.0.0 -m "添加一个tag1.0.0"
chuangchuang@chuang:~/work/temp/gittest[dev*]$ git tag
v1.0.0
3.2 查看该tag的信息
chuangchuang@chuang:~/work/temp/gittest[dev*]$ git show v1.0.0
tag v1.0.0
Tagger: chuang <chuangchuang.chen@cafintech.com>
Date: Sun Nov 12 19:52:26 2017 +0800
添加一个tag1.0.0
commit 45776d6cb67571cfe31656fb1d114e520c9e0ab2
Author: chuang <chuangchuang.chen@cafintech.com>
Date: Sun Nov 12 10:12:52 2017 +0800
di er ci ti jiao test
diff --git a/aa.txt b/aa.txt
index e69de29..e462656 100644
--- a/aa.txt
+++ b/aa.txt
@@ -0,0 +1 @@
+1 di yi ci wang li tian jia nei rong
3.3 查看当前最后一个commit
chuangchuang@chuang:~/work/temp/gittest[dev*]$ git log -1 --pretty=raw
commit 45776d6cb67571cfe31656fb1d114e520c9e0ab2
tree 68d98b1781c29d1df8b4ac7b6d457bccecf9756e
parent a3c8effc24eeb66de97a66b073c6d62c48fbc9ed
author chuang <chuangchuang.chen@cafintech.com> 1510452772 +0800
committer chuang <chuangchuang.chen@cafintech.com> 1510452772 +0800
di er ci ti jiao test
可以看到tag中显示的信息,追踪的是 id为 45776d6cb67571cfe31656fb1d114e520c9e0ab2
的最后一次commit
3.4 查看物理结构中的tag
再次查看.git中的tag(删减无用的)
.git/
├── branches
├── objects
│ ├── 45
│ │ └── 776d6cb67571cfe31656fb1d114e520c9e0ab2
│ ├── 68
│ ├── info
│ └── pack
└── refs
├── heads
│ ├── dev
│ └── master
├── remotes
│ └── origin
│ └── master
└── tags
└── v1.0.0
看看tags目录下的v1.0.0
chuangchuang@chuang:~/work/temp/gittest[dev*]$ cat .git/refs/tags/v1.0.0
c8ec46b8063b47a12de692106db06822945d4b09
里面存储了id为 c8ec46b8063b47a12de692106db06822945d4b09的文件名
再查看该文件的存储
chuangchuang@chuang:~/work/temp/gittest[dev*]$ git cat-file -p c8ec4
object 45776d6cb67571cfe31656fb1d114e520c9e0ab2
type commit
tag v1.0.0
tagger chuang <chuangchuang.chen@cafintech.com> 1510487546 +0800
添加一个tag1.0.0
可以看到这个里面已经关联到了commit
id为45776d6cb67571cfe31656fb1d114e520c9e0ab2
4 总结
branch 和 tag实际上都是关联到了 commit id
网友评论