简体   繁体   中英

How to use git describe on a detached head commit?

I have a main branch that has annotated-non-lightweight-tagged commits in it. The workspace is in a detached head state, ie after checked out via Jenkins Multibranch Pipeline

When I run git describe I am getting the name of a really old tag, together with a very high number of commits since that tag, (eg 1.0.0-459-abc1234 )

When I run git tag I get a list of all tags, including the most recent ones, that I am interested in, eg 3.1.0 , 3.2.0 .

I was then thinking about doing something like git branch -r --contains HEAD to get the name of the remote branch, then fetch and check that out (Running the risk that I am actually checking out a later commit than the one that triggered the pipeline, but whatever, it's isolated to a pull request anyways...) Or just run git describe <remote_branch_name> But neither of that worked. I don't understand why Git would prefer to show the very old tag instead of more recent ones, since any pull request is branched off the tag-containing master branch (every commit that had been tagged is guaranteed to be found on the master branch).

The reason for the problem might have been different git version actually. One host had a rather old git version installed (1.7.x) after upgrading to 2.10.x everywhere, the problem went away. Another possible reason could be that we sometimes updated tags, pointing them to a new commit (we stopped doing that.) I noticed at one point, that when you create a lightweight tag, and then change it to a annotated tag, another client that had already seen the lightweight tag, will not download the updated, now annotated tag, when you do git fetch --tags , because it recognizes it had already seen the tag by name, and does not bother that the type of the tag has changed, therefore git describe will not pick up that tag for that client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM