git saving a reference in the document, the principle is very simple
References principle
引用
I refer to is 提交记录
the reference
提交记录
used 哈希值
to uniquely identify
each 引用
represented by a file, save the file其引用的提交记录的哈希值
Reference classification
- Branch
- Variable, at different times can point
不同的提交记录
- Local branch
- The corresponding
.git/refs/heads/目录
files - Each
本地仓库
multiple本地分支
- The corresponding
- Remote branch
- The corresponding
.git/refs/remotes/<远端仓库名>/目录
files - Each
本地仓库
may correspond to a plurality远端仓库
, and each远端仓库
can have a plurality of远端分支
- The corresponding
- Variable, at different times can point
- tag
- The corresponding
.git/refs/tags/目录
files - Immutable, re-create deleted unless otherwise always points
特定的提交记录
- Each can have multiple git repository
tag
- The corresponding
- HEAD
- The corresponding
.git/HEAD
file - variable
- Usually points to a
本地分支
, that references to references - It may be pointed directly
某个提交记录
, referred toHEAD detached
, i.e. separated from the head pointer state - Can also point
tag
, git processed into such a situationHEAD detached
- Can also point
远端分支
, git processed into such a situationHEAD detached
- Usually points to a
- Each is only a git repository
HEAD
- It represents the current
工作区
detection file (or files before modification) which belongs to提交记录
the git checkout 指令
It is directed at changing HEADgit checkout 本地分支名
git checkout 提交记录哈希值
, detachedgit checkout 远端分支名
, detachedgit checkout tag名
, detached
- The corresponding
experiment
$ git checkout master
Switched to branch 'master'
$ cat .git/HEAD
ref: refs/heads/master
$ cat .git/refs/heads/master
89d496d44f93d107a7eb404890cd15a14ba8845d
After checkout master, HEAD points to master, master pointing 89d496
$ git checkout milestone
Note: checking out 'milestone'.
You are in 'detached HEAD' state.
HEAD is now at eecc5fe milestone
$ cat .git/HEAD
eecc5fe060e5b86957f931fd931beae4f206d4eb
After checkout tag milestone, HEAD pointing eecc5f, detached HEAD