git describe fails with “fatal: No names found, cannot describe anything.”

后端 未结 7 2071
梦如初夏
梦如初夏 2020-12-07 22:09

I\'m using git 1.7.1 on Ubuntu 10.10 amd64, and I\'m trying to extract the hash of my repository HEAD to use it in an automated version information that I compile into my pr

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 22:35

    I have had this problem in a CI build environment where the CI tool was performing a shallow clone of the repository. This was frustrating, because in my development environment, the command

    git describe --tags
    

    would give me output like

    2.2.12-7-g8ec9d6c9
    

    whereas in the build environment I would get the "fatal no names found" error. If I tried using the --always tag

    git describe --tags --always
    

    then I would simply get the hash of the latest commit, but not the most recent tag prior to that commit

    8ec9d6c9
    

    Performing a git pull in the build environment wouldn't help, because once the repo has been cloned shallowly, future pulls will not update the tags.

    The solution was to ensure that the initial clone of the repo in the build environment was not a shallow clone (i.e. the git clone command was not used with --depth, --shallow-since or --shallow-exclude parameters).

提交回复
热议问题