git references acquaintance (HEAD, branch, tag)

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本地分支
    • Remote branch
      • The corresponding .git/refs/remotes/<远端仓库名>/目录files
      • Each 本地仓库may correspond to a plurality 远端仓库, and each 远端仓库can have a plurality of远端分支
  • tag
    • The corresponding .git/refs/tags/目录files
    • Immutable, re-create deleted unless otherwise always points特定的提交记录
    • Each can have multiple git repositorytag
  • HEAD
    • The corresponding .git/HEADfile
    • variable
      • Usually points to a 本地分支, that references to references
      • It may be pointed directly 某个提交记录, referred to HEAD 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
    • Each is only a git repositoryHEAD
    • It represents the current 工作区detection file (or files before modification) which belongs to 提交记录the
    • git checkout 指令It is directed at changing HEAD
      • git checkout 本地分支名
      • git checkout 提交记录哈希值, detached
      • git checkout 远端分支名, detached
      • git checkout tag名, detached

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

Guess you like

Origin www.cnblogs.com/milesgo517/p/10993188.html