Git command to display HEAD commit id?

前端 未结 9 1720
轮回少年
轮回少年 2020-12-22 15:27

What command can I use to print out the commit id of HEAD?

This is what I\'m doing by hand:

$ cat .git/HEAD
ref: refs/heads/v3.3
$ cat .git/refs/head         


        
相关标签:
9条回答
  • 2020-12-22 15:33

    git rev-parse --abbrev-ref HEAD

    0 讨论(0)
  • 2020-12-22 15:35

    You can use

    git log -g branchname
    

    to see git reflog information formatted like the git log output

    0 讨论(0)
  • 2020-12-22 15:37

    According to https://git-scm.com/docs/git-log, for more pretty output in console you can use --decorate argument of git-log command:

    git log --pretty=oneline --decorate
    

    will print:

    2a5ccd714972552064746e0fb9a7aed747e483c7 (HEAD -> master) New commit
    fe00287269b07e2e44f25095748b86c5fc50a3ef (tag: v1.1-01) Commit 3
    08ed8cceb27f4f5e5a168831d20a9d2fa5c91d8b (tag: v1.1, tag: v1.0-0.1) commit 1
    116340f24354497af488fd63f4f5ad6286e176fc (tag: v1.0) second
    52c1cdcb1988d638ec9e05a291e137912b56b3af test
    
    0 讨论(0)
  • 2020-12-22 15:39

    Old thread, still for future reference...:) even following works

    git show-ref --head
    

    by default HEAD is filtered out. Be careful about following though ; plural "heads" with a 's' at the end. The following command shows branches under "refs/heads"

     git show-ref --heads
    
    0 讨论(0)
  • 2020-12-22 15:48

    You can specify git log options to show only the last commit, -1, and a format that includes only the commit ID, like this:

    git log -1 --format=%H

    If you prefer the shortened commit ID:

    git log -1 --format=%h

    0 讨论(0)
  • 2020-12-22 15:49

    You can use this command

    $ git rev-list HEAD

    You can also use the head Unix command to show the latest n HEAD commits like

    $ git rev-list HEAD | head - 2

    0 讨论(0)
提交回复
热议问题