How to show git commit using number of commits since a tag

后端 未结 8 1176
执笔经年
执笔经年 2021-02-05 07:39

With git describe you can get the number of commits since the last tag. If you only had the tag and the number of commits what is the best way to show the commit t

8条回答
  •  青春惊慌失措
    2021-02-05 08:21

    What you're asking for is impossible in the general case. The number of commits alone can't tell you anything if there are any merges in your history.

    For example, given the following repo structure:

    a - b - c - d - h
      \           /
        e - f - g
    

    With a tag put on a, the outputs of git describe d and git describe g are identical save for the SHA1:

    > git describe d
    tag-3-ge8dca33
    > git describe g
    tag-3-g4fecc2e
    

    That said, if you don't have a bunch of parallel branches going on at once, then you may be able to resolve a given commit number back to a single commit, but if you have even a single active side branch at the time of your tag then this may not work.

    If you need reliable release numbers, you should stick to explicit tags.

提交回复
热议问题