问题描述
如果我将 git commit --amend
添加到标记提交中,标记将会消失。我需要删除原始标签并再次添加。有没有办法将原始标签移动到新的提交?
您需要移动标记(保留其旧消息)并删除/替换远程标记。
有一个来促进这个顺序:
#标签的返回日期。 (用于别名)
tag-date =!git show $ 1 | awk'{if($ 1 == \Date:\){print substr($ 0,index($ 0,$ 3) )}}'| tail -2 | head -1#
#显示标签消息
tag-message =!git show $ 1 | awk -v capture = 0'{if capture)message = message \\\\\
\$ 0}; BEGIN {message = \\}; {if($ 1 == \Date:\&& length (message)== 0){capture = 1}; if($ 1 == \commit\){capture = 0}}; END {print message}'| sed'$ d'| cat -s#
###移动标签。使用:git tagm<标记名称> < newcommit>
tagm =!GIT_TAG_MESSAGE = $(git tag-message $ 1)&& GIT_COMMITTER_DATE = $(git tag-date $ 1)&&&&git tag-message $ 1&&& git tag -d $ 1 && git标记-a $ 1 $ 2 -m \$ GIT_TAG_MESSAGE\#
###移动推送标签。使用:git tagmp<标记名> < newcommit>
tagmp =!git tagm $ 1 $ 2&& git push --delete origin $ 1&& git push origin $ 1#
一旦您修改了提交(使用新的SHA1),您应该输入:
git tagm< yourTag> < SHA>
If I do git commit --amend
to a tagged commit, the tag will disappeared. I need to delete the original tag and add it again. Is there any way to move the original tag to the new commit?
You cannot directly tie the creation of a new commit (--amend
) and a tag (which still references the original commit).
You would need to move the tag (keeping its old message) and delete/replace the tag on remote.
Juan Antonio Tubío has an interesting set of alias to facilitate that sequence:
# Return date of tag. (To use in another alias)
tag-date = "!git show $1 | awk '{ if ($1 == \"Date:\") { print substr($0, index($0,$3)) }}' | tail -2 | head -1 #"
# Show tag message
tag-message = "!git show $1 | awk -v capture=0 '{ if(capture) message=message\"\\n\"$0}; BEGIN {message=\"\"}; { if ($1 == \"Date:\" && length(message)==0 ) {capture=1}; if ($1 == \"commit\" ) {capture=0} }; END { print message }' | sed '$ d' | cat -s #"
### Move tag. Use: git tagm <tagname> <newcommit>
tagm = "!GIT_TAG_MESSAGE=$(git tag-message $1) && GIT_COMMITTER_DATE=$(git tag-date $1) && git tag-message $1 && git tag -d $1 && git tag -a $1 $2 -m \"$GIT_TAG_MESSAGE\" #"
### Move pushed tag. Use: git tagmp <tagname> <newcommit>
tagmp = "!git tagm $1 $2 && git push --delete origin $1 && git push origin $1 #"
Once you have amended your commit (with a new SHA1 ), you would type:
git tagm <yourTag> <sha>
这篇关于如何在执行commit -amend时自动更新git标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!