In Git, is there a way to get the “friendly” name for an arbitrary commit?

前端 未结 2 2098
礼貌的吻别
礼貌的吻别 2020-12-10 11:15

In Git, there are numerous ways to refer to a commit, including the full SHA hash or a shortened form of the hash (say, the first 6 characters or so). You can also name comm

相关标签:
2条回答
  • 2020-12-10 12:07

    Try git describe:

    $ git describe --all --contains 90de2680dc54c0d600b0694bd175bd09357a8dba
    master~2
    
    0 讨论(0)
  • 2020-12-10 12:12

    You can use "git name-rev" to get the form you are asking about. One problem with that form is that, being relative to a branch, it isn't a permanent name. So an alternative is "git describe" which produces an alternative friendly name based on how far ahead of a tag a given commit is.

    For example:

    srh@devo16:~/src/git <master>$ git name-rev 3cd7388
    3cd7388 master~2
    

    But then after I do a "git pull", master~2 could mean something else. By contrast:

    srh@devo16:~/src/git <master>$ git describe 3cd7388
    v1.6.3.1-153-g3cd7388
    

    Now "v1.6.3.1-153-g3cd7388" is a permanent name. Of course, it's still a bit long (although you can shorten the hash bit on the end by specifying "--abbrev=4" for example) but it communicates that 3cd7388 is 153 changes after version 1.6.3.1.

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