如何删除已推送的Git标记?
当前回答
这里有一个本地测试用例,可以在本地测试而不干扰远程设备:
~/p $ mkdir gittest
~/p/git $ cd gittest/
~/p/gittest $ git init
Initialized empty Git repository in /Users/local_user/p/gittest/.git/
~/p/gittest $ touch testfile.txt
~/p/gittest $ git add testfile.txt
~/p/gittest $ git commit -m "initial commit"
[master (root-commit) 912ce0e] initial commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 testfile.txt
~/p/gittest $ git tag
~/p/gittest $ git tag -a testtag
~/p/gittest $ git tag
testtag
~/p/gittest $ git show-ref
912ce0e40635c90241fdab756dce7ea34938de57 refs/heads/master
b0a6c15cabb990e6d6c46f762891b63608d962f3 refs/tags/testtag
~/p/gittest $ cd ..
~/p $ mkdir gitbare
~/p $ cd gitbare
~/p/gitbare $ git init --bare
Initialized empty Git repository in /Users/local_user/p/gitbare/
~/p/gitbare $ cd ..
~/p $ cd gittest/
~/p/gittest $ git remote add origin /Users/local_user/p/gitbare
~/p/gittest $ git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 215 bytes | 215.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /Users/local_user/p/gitbare
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
~/p/gittest $ git push origin testtag
Counting objects: 1, done.
Writing objects: 100% (1/1), 163 bytes | 163.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To /Users/local_user/p/gitbare
* [new tag] testtag -> testtag
~/p/gittest $ git show-ref
912ce0e40635c90241fdab756dce7ea34938de57 refs/heads/master
912ce0e40635c90241fdab756dce7ea34938de57 refs/remotes/origin/master
b0a6c15cabb990e6d6c46f762891b63608d962f3 refs/tags/testtag
~/p/gittest $ git push -d origin testtag
To /Users/local_user/p/gitbare
- [deleted] testtag
~/p/gittest git tag -d testtag
Deleted tag 'testtag' (was b0a6c15)
~/p/gittest $ git show-ref
912ce0e40635c90241fdab756dce7ea34938de57 refs/heads/master
912ce0e40635c90241fdab756dce7ea34938de57 refs/remotes/origin/master
~/p/gittest
其他回答
如果您在Git存储库中创建了一个名为release01的标记,您可以通过执行以下操作将其从存储库中删除:
git tag -d release01
git push origin :refs/tags/release01
要从Mercurial存储库中删除一个:
hg tag --remove featurefoo
请参考https://confluence.atlassian.com/pages/viewpage.action?pageId=282175551
git tag -d your_tag_name
git push origin :refs/tags/your_tag_name
第一行从本地回购中删除your_tag_name,第二行从远程回购中删除您的_tag_name。
对于使用GitHub的人来说,还需要一个步骤:丢弃草稿。
用于数千个远程标签的速度快100倍
在阅读了这些答案,同时需要删除11000多个标签之后,我了解到这些方法依赖于xargs,或者xargs耗时太长,除非你有几个小时可以燃烧。
在挣扎中,我找到了两种更快的方法。对于这两种情况,从git-tag或git-ls-remote-tag开始,列出要删除的远程标记。在下面的示例中,您可以省略sorting_processing_etc,或将其替换为所需的任何greping、sorting、tailing或head(例如grep-P“my_regex”|sort|head-n-200等):
第一种方法是迄今为止最快的,可能比使用xargs快20到100倍,一次至少可以处理几千个标签。
git push origin $(< git tag | sorting_processing_etc \
| sed -e 's/^/:/' | paste -sd " ") #note exclude "<" for zsh
这是如何工作的?正常的、以行分隔的标记列表被转换为一行以空格分隔的标记,每个标记都以:so。
tag1 becomes
tag2 ======> :tag1 :tag2 :tag3
tag3
将git push与此格式标记一起使用,不会将任何内容推送到每个远程引用中,并将其删除(以这种方式推送的正常格式是local_ref_path:remote_ref_path)。
方法二在同一页的其他地方作为单独的答案
在这两种方法之后,您可能也希望删除本地标记。这要快得多,所以我们可以返回使用xargs和git标记-d,这就足够了。
git tag | sorting_processing_etc | xargs -L 1 git tag -d
或类似于远程删除:
git tag -d $(< git tag | sorting_processing_etc | paste -sd " ")
更直接的方法是
git push --delete origin YOUR_TAG_NAME
在这种情况下,IMO前缀冒号语法有点奇怪
在终端上,执行以下操作:
git fetch
git tag
git tag -d {tag-name}
git push origin :refs/tags/{tag-name}
现在转到Github.com并刷新,它们就会消失。
推荐文章
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别
- GitHub -致命:无法读取用户名https://github.com':没有这样的文件或目录
- 撤消git平分错误
- 使用.gitconfig配置diff工具
- 如何配置Mac OS X术语,使git有颜色?
- Visual Studio Code: .git文件夹/文件隐藏
- “node_modules”文件夹应该包含在git存储库中吗
- 为什么git-rebase给了我合并冲突,而我所做的只是压缩提交?
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 如何从远程分支中挑选?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别