What is the HEAD in git?

前端 未结 6 2076
有刺的猬
有刺的猬 2020-12-02 03:59

There seems to be a difference between the last commit, the HEAD and the state of the file I can see in my directory.

What is HEAD, what can I do with it and what mi

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 04:30

    Basically HEAD is a pointer/reference which points to the last commit in the current branch.

    You can use these two commands to verify this.

    $ git log -1
    
    commit 9883e13257f2e7555eb6e3b14b2c814978c75692 (HEAD -> MyLocalBranch)
    Author: vikram 
    Date:   Sun Oct 11 23:32:45 2020 -0400
    this is my last commit message
    

    Now use below command to see where HEAD is pointing:

    $ git rev-parse HEAD
    9883e13257f2e7555eb6e3b14b2c814978c75692
    

    As you can see that these two commit hashes are the same. So HEAD always points to the latest/last commit in the current branch.

提交回复
热议问题