Phr*_*ogz 109
警告:这不会保留带注释标签的标签消息.
对于需要更改的每个标记:
在代码中:
# Fixing tag named '1.0.1'
git checkout 1.0.1 # Go to the associated commit
git tag -d 1.0.1 # Locally delete the tag
git push origin :refs/tags/1.0.1 # Push this deletion up to GitHub
# Create the tag, with a date derived from the current head
GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" git tag -a 1.0.1 -m"v1.0.1"
git push --tags # Send the fixed tags to GitHub
Run Code Online (Sandbox Code Playgroud)
根据如何在Git中标记:
如果您忘记标记版本或版本凹凸,您可以始终追溯标记它,如下所示:
Run Code Online (Sandbox Code Playgroud)git checkout SHA1_OF_PAST_COMMIT git tag -m"Retroactively tagging version 1.5" v1.5虽然这是完全可用的,但它可以使您的标签不按时间顺序排列,这可以与寻找"最新"标签的构建系统相混淆.但不要害怕.莱纳斯想到了一切:
Run Code Online (Sandbox Code Playgroud)# This moves you to the point in history where the commit exists git checkout SHA1_OF_PAST_COMMIT # This command gives you the datetime of the commit you're standing on git show --format=%aD | head -1 # And this temporarily sets git tag's clock back to the date you copy/pasted in from above GIT_COMMITTER_DATE="Thu Nov 11 12:21:57 2010 -0800" git tag -a 0.9.33 -m"Retroactively tagging version 0.9.33" # Combining the two... GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" git tag -a 0.9.33 -m"Retroactively tagging version 0.9.33"
但是,如果您已经添加了标记,则无法使用上述内容,git tag -f existingtag否则当您尝试合并时git会抱怨:
Rammy:docubot phrogz$ git push --tags
To git@github.com:Phrogz/docubot.git
! [rejected] 1.0.1 -> 1.0.1 (already exists)
error: failed to push some refs to 'git@github.com:Phrogz/docubot.git'
hint: Updates were rejected because the tag already exists in the remote.
Run Code Online (Sandbox Code Playgroud)
相反,您必须在本地删除标记:
git tag -d 1.0.1
Run Code Online (Sandbox Code Playgroud)
远程推送该删除:
git push origin :refs/tags/1.0.1
Run Code Online (Sandbox Code Playgroud)
在GitHub上,重新加载版本 - 该版本现已标记为"草稿" - 并删除草稿.
现在,根据上面的说明添加回溯标记,最后将生成的标记推送到GitHub:
git push --tags
Run Code Online (Sandbox Code Playgroud)
然后再次重新添加GitHub发布信息.
vmr*_*rob 17
这是基于其他答案中的一些评论的单行:
git tag -l | while read -r tag ; do COMMIT_HASH=$(git rev-list -1 $tag) && GIT_COMMITTER_DATE="$(git show $COMMIT_HASH --format=%aD | head -1)" git tag -a -f $tag -m"$tag" $COMMIT_HASH ; done && git push --tags --force
Run Code Online (Sandbox Code Playgroud)
警告:这将破坏您的上游标签,并且不会保留带注释标签的消息!确保你知道你正在做什么,并且确定不要为公共存储库做这个!
打破它...
# Loop over tags
git tag -l | while read -r tag
do
# get the commit hash of the current tag
COMMIT_HASH=$(git rev-list -1 $tag)
# get the commit date of the tag and create a new tag using
# the tag's name and message. By specifying the environment
# environment variable GIT_COMMITTER_DATE before this is
# run, we override the default tag date. Note that if you
# specify the variable on a different line, it will apply to
# the current environment. This isn't desired as probably
# don't want your future tags to also have that past date.
# Of course, when you close your shell, the variable will no
# longer persist.
GIT_COMMITTER_DATE="$(git show $COMMIT_HASH --format=%aD | head -1)" git tag -a -f $tag -m"$tag" $COMMIT_HASH
done
# Force push tags and overwrite ones on the server with the same name
git push --tags --force
Run Code Online (Sandbox Code Playgroud)
感谢@Mr_and_Mrs_D建议使用单次推送.
在其他答案的基础上,这是一种保留标签消息第一行的方法
git tag -l | while read -r tag ; do COMMIT_HASH=$(git rev-list -1 $tag) COMMIT_MSG=$(git tag -l --format='%(contents)' $tag | head -n1) && GIT_COMMITTER_DATE="$(git show $COMMIT_HASH --format=%aD | head -1)" git tag -a -f $tag -m"$COMMIT_MSG" $COMMIT_HASH ; done
git tag -l -n1 #check by listing all tags with first line of message
git push --tags --force #push edited tags up to remote
Run Code Online (Sandbox Code Playgroud)
负责保存消息的位是:
COMMIT_MSG=$(git tag -l --format='%(contents)' $tag | head -n1)
Run Code Online (Sandbox Code Playgroud)
head -n1将采用旧提交消息的第一行。您可以将其修改为-n2或-n3等以获得两行或三行。
如果您只想更改一个标签的日期/时间,可以通过以下方式分解单行代码以在 bash shell 中执行此操作:
tag=v0.1.0
COMMIT_HASH=$(git rev-list -1 $tag)
COMMIT_MSG=$(git tag -l --format='%(contents)' $tag | head -n1)
COMMIT_DATE=$(git show $COMMIT_HASH --format=%aD | head -1)
GIT_COMMITTER_DATE=$COMMIT_DATE git tag -s -a -f $tag -m"$COMMIT_MSG" $COMMIT_HASH
Run Code Online (Sandbox Code Playgroud)
参考: