Can a lightweight tag be converted to an annotated tag?

我的梦境 提交于 2019-11-28 18:37:20

A lightweight tag is just a 'ref' that points at that commit. You can force-create a new annotated tag on top of the old tag:

git tag -a -f <tagname> <tagname>

As of Git v1.8.2, you need to use --force to replace any tags on a remote with git push, even if you are replacing a lightweight tag with something that is effectively a fast-forward or a true tag object pointing at the same commit as the existing tag reference.

git push --force origin <tagname>
SamB

Based on Charles' answer and on this blog post, I think it is better to use something like this:

#!/bin/sh
tag=$1
date="$(git show $tag --format=%aD | head -1)"
GIT_COMMITTER_DATE="$date" git tag -a -f $tag $tag

You can also simply use git describe --tags to also include lightweight tags in the search.

Convert all tags to annotated (based on Charles Bailey's example and Ferenc Wágner's comment):

for tag in $(git tag -l); do git tag -a -f $tag $tag^0 -m $tag; done
git push --tags --force
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!