如何删除远程标签?

发布于 2024-10-28 08:01:49 字数 24 浏览 4 评论 0 原文

如何删除已经推送的 Git 标签?

How can I delete a Git tag that has already been pushed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(28

怪我太投入 2024-11-04 08:01:50

如果你使用PowerShell,并且你想删除一堆:

# Local tags:
git tag -l | foreach { git tag -d $_ }

# Remote tags:
git tag -l | foreach { git push --delete origin $_ }

当然,你也可以在删除之前过滤它们:

git tag -l | Where-Object { $_ -like "build-*" } | foreach { git tag -d $_ }

If you're using PowerShell, and you want to delete a bunch of them:

# Local tags:
git tag -l | foreach { git tag -d $_ }

# Remote tags:
git tag -l | foreach { git push --delete origin $_ }

Of course, you can also filter them before deleting:

git tag -l | Where-Object { $_ -like "build-*" } | foreach { git tag -d $_ }
寄人书 2024-11-04 08:01:50

正如 @CubanX 所建议的,我已经将这个答案与原来的答案分开:

这是一种比 xargs 快几倍的方法,并且可以通过调整来扩展更多。它使用 Github API、个人访问令牌和利用实用程序parallel

git tag | sorting_processing_etc | parallel --jobs 2 curl -i -X DELETE \ 
https://api.github.com/repos/My_Account/my_repo/git/refs/tags/{} -H 
\"authorization: token GIT_OAUTH_OR_PERSONAL_KEY_HERE\"  \
-H \"cache-control: no-cache\"`

parallel 有多种操作模式,但通常可以并行化任何模式你给它的命令同时允许你设置进程数量的限制。您可以更改 --jobs 2 参数以允许更快的操作,但我在使用 Github 的 速率限制,目前为 5000/小时,但似乎也有未记录的短期限制。


之后,您可能还想删除本地标签。
这要快得多,因此我们可以返回使用 xargs 和 git tag -d ,这已经足够了。

git tag | sorting_processing_etc | xargs -L 1 git tag -d

As @CubanX suggested, I've split this answer from my original:

Here is a method which is several times faster than xargs and may scale much more with tweaking. It uses the Github API, a personal access token, and leverages the utility parallel.

git tag | sorting_processing_etc | parallel --jobs 2 curl -i -X DELETE \ 
https://api.github.com/repos/My_Account/my_repo/git/refs/tags/{} -H 
\"authorization: token GIT_OAUTH_OR_PERSONAL_KEY_HERE\"  \
-H \"cache-control: no-cache\"`

parallel has many operating modes, but generally parallelizes any command you give it while allowing you to set limits on the number of processes. You can alter the --jobs 2 parameter to allow faster operation, but I had problems with Github's rate limits, which are currently 5000/hr, but also seems to have an undocumented short-term limit as well.


After this, you'll probably want to delete your local tags too.
This is much faster so we can go back to using xargs and git tag -d, which is sufficient.

git tag | sorting_processing_etc | xargs -L 1 git tag -d
花海 2024-11-04 08:01:50

我想删除除与模式匹配的标签之外的所有标签,以便我可以删除除最后几个月之外的所有生产标签,这是我取得巨大成功的方法:

删除所有远程标签和标签。从删除中排除表达式

git tag -l | grep -P '^(?!Production-2017-0[89])' | xargs -n 1 git push --delete origin

删除所有本地标签和表达式从删除中排除表达式

git tag -l | grep -P '^(?!Production-2017-0[89])' | xargs git tag -d

I wanted to remove all tags except for those that match a pattern so that I could delete all but the last couple of months of production tags, here's what I used to great success:

Delete All Remote Tags & Exclude Expression From Delete

git tag -l | grep -P '^(?!Production-2017-0[89])' | xargs -n 1 git push --delete origin

Delete All Local Tags & Exclude Expression From Delete

git tag -l | grep -P '^(?!Production-2017-0[89])' | xargs git tag -d
腹黑女流氓 2024-11-04 08:01:50

对于乌龟 git 用户来说,在数百个标签的规模下,您可以使用 UI 一次删除多个标签,但 UI 很好地隐藏在上下文菜单下。

从资源管理器窗口右键单击 ->浏览参考资料 ->右键单击 ref/refmotes/name ->选择“删除远程标签”

在此处输入图像描述

请参阅 https://tortoisegit.org/docs/tortoisegit/tgit-dug-browse-ref.html

For tortoise git users, at a scale of hundreds tags, you can delete multiple tags at once using UI, but the UI is well hidden under context menu.

From explorer windows right click -> Browse references -> Right click on ref/refmotes/name -> choose 'Delete remote tags'

enter image description here

See https://tortoisegit.org/docs/tortoisegit/tgit-dug-browse-ref.html

天暗了我发光 2024-11-04 08:01:50

如果您创建了以#字符开头的标签,例如#ST002,您可能会发现无法使用正常模式删除。即

git tag -d #STOO2

不会删除该标签,而是将其包装在 String Literal 中,如下所示,

git tag -d "#ST002" or git tag -d '#ST002'

这会将其删除。希望它能帮助那些犯了使用#书写标签名称错误的人。

If you have a tag created starting with the # character, e.g. #ST002, you might find that u are unable to delete using normal patterns. i.e.

git tag -d #STOO2

Will not delete the tag, but wrapping it in a String Literal like so

git tag -d "#ST002" or git tag -d '#ST002'

That will get it deleted. Hoping it will help someone who made the mistake of using # to write tag names.

笑,眼淚并存 2024-11-04 08:01:50

看起来 xargs 已经做了很多工作。回顾这个线程,我猜测您遇到的 xargs 缓慢是因为原始答案在实际上不需要时使用了 xargs -n 1

这与您的方法一相同,只是 xargs 自动处理最大命令行长度:

git tag | sorting_processing_etc | xargs git push --delete origin

xargs 也可以并行运行进程。方法 2 使用 xargs

git tag | sorting_processing_etc | xargs -P 5 -n 100 git push --delete origin

上面最多使用 5 个进程,每个进程最多处理 100 个参数。您可以尝试这些参数,找到最适合您需求的方法。

Seems like a lot of work for something xargs already does. Looking back through this thread, I'm guessing the slowness with xargs that you experienced is because the original answer used xargs -n 1 when it didn't really need to.

This is equivalent to your method one except that xargs automatically deals with the maximum command line length:

git tag | sorting_processing_etc | xargs git push --delete origin

xargs can run processes in parallel too. Method 2 with xargs:

git tag | sorting_processing_etc | xargs -P 5 -n 100 git push --delete origin

The above uses a maximum of 5 processes to handle a maximum of 100 arguments in each process. You can experiment with the arguments to find what works best for your needs.

深陷 2024-11-04 08:01:50

只是想分享我创建的别名,它可以做同样的事情:

将以下内容添加到您的 ~/.gitconfig

[alias]
    delete-tag = "!f() { \
            echo 'deleting tag' $1 'from remote/origin ausing command: git push --delete origin tagName;'; \
            git push --delete origin $1; \
            echo 'deleting tag' $1 'from local using command: git tag -d tagName;'; \
            git tag -d $1; \
        }; f"

用法如下:

-->git delete-tag v1.0-DeleteMe
deleting tag v1.0-DeleteMe from remote/origin ausing command: git push --delete origin tagName;
To https://github.com/jsticha/pafs
 - [deleted]             v1.0-DeleteMe
deleting tag v1.0-DeleteMe from local using command: git tag -d tagName;
Deleted tag 'v1.0-DeleteMe' (was 300d3ef22)

Just wanted to share an alias I created which does the same thing:

Add the following to your ~/.gitconfig

[alias]
    delete-tag = "!f() { \
            echo 'deleting tag' $1 'from remote/origin ausing command: git push --delete origin tagName;'; \
            git push --delete origin $1; \
            echo 'deleting tag' $1 'from local using command: git tag -d tagName;'; \
            git tag -d $1; \
        }; f"

The usage looks like:

-->git delete-tag v1.0-DeleteMe
deleting tag v1.0-DeleteMe from remote/origin ausing command: git push --delete origin tagName;
To https://github.com/jsticha/pafs
 - [deleted]             v1.0-DeleteMe
deleting tag v1.0-DeleteMe from local using command: git tag -d tagName;
Deleted tag 'v1.0-DeleteMe' (was 300d3ef22)
笙痞 2024-11-04 08:01:50

这是一个本地测试用例,可以在本地测试它,而无需干扰远程:

~/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

Here is a local testcase to test it locally without messing with a remote:

~/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
记忆消瘦 2024-11-04 08:01:50

这里已经有很多好的答案,但是如果您需要删除所有标签,可以使用使用 PowerShell 的这个衬垫:

foreach($tag in (git tag)) { git tag -d $tag 。修剪(); git push origin :refs/tags/$tag }

这里,我们获取所有标签的列表,删除每个本地标签,然后删除远程标签(在 GitHub 上测试)。

There are a lot of good answers here already, but if you ever need to delete all the tags, this one liner using PowerShell can be used:

foreach($tag in (git tag)) { git tag -d $tag.Trim(); git push origin :refs/tags/$tag }

Here, we get the list of all tags, delete each local tag followed by deleting the remote tag (tested on GitHub).

神经大条 2024-11-04 08:01:50

这对我有用

git push --force origin refs/tags/<tag_name>:refs/tags/<tag_name>

This worked for me

git push --force origin refs/tags/<tag_name>:refs/tags/<tag_name>
雨落□心尘 2024-11-04 08:01:49

您可以将“空”引用推送到远程标记名称:

git push origin :tagname

或者,更明确地说,使用 --delete 选项(或 -d 如果您的 git 版本低于1.8.0):

git push --delete origin tagname

请注意,git 具有标记命名空间和分支命名空间,因此您可以对分支和标记使用相同的名称。如果你想确保你不会意外删除分支而不是标签,你可以指定完整的引用,这将永远不会删除分支:

git push origin :refs/tags/tagname

如果你还需要删除本地标签,请使用:

git tag --delete tagname

后台

推送分支、标签或对远程存储库的其他引用涉及指定“哪个存储库、什么源、什么目的地?”

git push remote-repo source-ref:destination-ref

一个将 master 分支推送到源的 master 分支的真实示例是:

git push origin refs/heads/master:refs/heads/master

由于默认路径,可以缩短为:

git push origin master:master

标签的工作方式相同:

git push origin refs/tags/release-1.0:refs/tags/release-1.0

也可以缩短为:

git push origin release-1.0:release-1.0

通过省略源引用(之前的部分)冒号),您将“无”推送到目的地,删除远程端的引用。

You can push an 'empty' reference to the remote tag name:

git push origin :tagname

Or, more expressively, use the --delete option (or -d if your git version is older than 1.8.0):

git push --delete origin tagname

Note that git has tag namespace and branch namespace so you may use the same name for a branch and for a tag. If you want to make sure that you cannot accidentally remove the branch instead of the tag, you can specify full ref which will never delete a branch:

git push origin :refs/tags/tagname

If you also need to delete the local tag, use:

git tag --delete tagname

Background

Pushing a branch, tag, or other ref to a remote repository involves specifying "which repo, what source, what destination?"

git push remote-repo source-ref:destination-ref

A real world example where you push your master branch to the origin's master branch is:

git push origin refs/heads/master:refs/heads/master

Which because of default paths, can be shortened to:

git push origin master:master

Tags work the same way:

git push origin refs/tags/release-1.0:refs/tags/release-1.0

Which can also be shortened to:

git push origin release-1.0:release-1.0

By omitting the source ref (the part before the colon), you push 'nothing' to the destination, deleting the ref on the remote end.

因为看清所以看轻 2024-11-04 08:01:49

更直接的方法是

git push --delete origin YOUR_TAG_NAME

IMO 前缀冒号语法在这种情况下有点奇怪

A more straightforward way is

git push --delete origin YOUR_TAG_NAME

IMO prefixing colon syntax is a little bit odd in this situation

夏九 2024-11-04 08:01:49

如果您有要删除的远程标记 v0.1.0,并且您的远程标记为 origin,则只需:

git push origin :refs/tags/v0.1.0

如果您还需要在本地删除该标记:

git tag -d v0.1.0

请参阅 Adam Franco 的回答,解释了 Git 不寻常的 : 删除语法。

If you have a remote tag v0.1.0 to delete, and your remote is origin, then simply:

git push origin :refs/tags/v0.1.0

If you also need to delete the tag locally:

git tag -d v0.1.0

See Adam Franco's answer for an explanation of Git's unusual : syntax for deletion.

轻许诺言 2024-11-04 08:01:49

删除所有本地标签并获取远程标签列表

git tag -l | xargs git tag -d
git fetch

删除所有远程标签

git tag -l | xargs -n 1 git push --delete origin

清理本地标签

git tag -l | xargs git tag -d

Delete all local tags and get the list of remote tags:

git tag -l | xargs git tag -d
git fetch

Remove all remote tags

git tag -l | xargs -n 1 git push --delete origin

Clean up local tags

git tag -l | xargs git tag -d
带刺的爱情 2024-11-04 08:01:49

git push --delete origin $TAGNAME 是正确的方法(除了本地删除之外)。

但是:请确保使用 Git 2.31+(2021 年第一季度)。

git push $there --delete (man) 应该已被诊断出来作为一个错误,而是变成了匹配的推送,并已使用 Git 2.31(2021 年第一季度)进行了更正。

请参阅 提交 20e4164(2021 年 2 月 23 日) .com/gitster" rel="noreferrer">Junio C Hamano (gitster)。
(由 Junio C Hamano -- gitster -- 合并于 提交 1400458,2021 年 2 月 25 日)

推送:不要转动- -将 '' 删除到匹配的推送中

注意到者:蒂尔曼·沃格尔

当我们添加语法糖“ git Push Remote --删除"(man) 到“git 推送"(man) 作为规范 git 推送远程(man) :语法位于 f517f1f ("内置推送: 添加(man) --delete 作为 :foo 的语法糖", 2009-12-30, Git v1.7.0-rc0 -- 合并),我们不够仔细,无法确保 不为空。

盲目地将“--delete ”重写为“:”意味着空字符串 结果是 refspec“:”,这是请求“匹配”推送且不会删除任何内容的语法。

更糟糕的是,如果有可以快进的匹配参考,它们就会过早发布,即使用户觉得它们还没有准备好被推出,这将是一场真正的灾难。

git push --delete origin $TAGNAME is the correct approach (in addition of a local delete).

But: make sure to use Git 2.31+ (Q1 2021).

"git push $there --delete"(man) should have been diagnosed as an error, but instead turned into a matching push, which has been corrected with Git 2.31 (Q1 2021).

See commit 20e4164 (23 Feb 2021) by Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit 1400458, 25 Feb 2021)

push: do not turn --delete '' into a matching push

Noticed-by: Tilman Vogel

When we added a syntax sugar "git push remote --delete"(man) <ref> to "git push"(man) as a synonym to the canonical git push remote(man) : syntax at f517f1f ("builtin-push: add(man) --delete as syntactic sugar for :foo", 2009-12-30, Git v1.7.0-rc0 -- merge), we weren't careful enough to make sure that <ref> is not empty.

Blindly rewriting "--delete <ref>" to ":<ref>" means that an empty string <ref> results in refspec ":", which is the syntax to ask for "matching" push that does not delete anything.

Worse yet, if there were matching refs that can be fast-forwarded, they would have been published prematurely, even if the user feels that they are not ready yet to be pushed out, which would be a real disaster.

恏ㄋ傷疤忘ㄋ疼 2024-11-04 08:01:49

从您的终端执行以下操作:

git fetch
git tag
git tag -d {tag-name}
git push origin :refs/tags/{tag-name}

现在转到 Github.com 并刷新,它们就会消失。

From your terminal, do this:

git fetch
git tag
git tag -d {tag-name}
git push origin :refs/tags/{tag-name}

Now go to Github.com and refresh, they disappear.

不打扰别人 2024-11-04 08:01:49
git tag -d your_tag_name
git push origin :refs/tags/your_tag_name

第一行从本地存储库中删除your_tag_name,第二行从远程存储库中删除your_tag_name

对于那些使用 GitHub 的人来说,还需要一步:丢弃草稿
输入图像描述这里

git tag -d your_tag_name
git push origin :refs/tags/your_tag_name

The first line deletes your_tag_name from local repo and second line deletes your_tag_name from remote repo.

For those who use GitHub, one more step is needed: discarding draft.
enter image description here

方觉久 2024-11-04 08:01:49

这两个步骤效果很好:

# delete local tag '1.0.0'
git tag -d 1.0.0

# delete remote tag '1.0.0' (eg, GitHub version too)
git push origin :refs/tags/1.0.0

This two steps works fine:

# delete local tag '1.0.0'
git tag -d 1.0.0

# delete remote tag '1.0.0' (eg, GitHub version too)
git push origin :refs/tags/1.0.0
江湖彼岸 2024-11-04 08:01:49

要从远程存储库中删除标签:

git push --delete origin TAGNAME

您可能还想在本地删除标签:

git tag -d TAGNAME

To remove the tag from the remote repository:

git push --delete origin TAGNAME

You may also want to delete the tag locally:

git tag -d TAGNAME
墨落画卷 2024-11-04 08:01:49

这对我个人来说是最快的方法:

首先在本地删除:

git tag --delete <tagname>

然后在远程删除:

git push --delete origin <tagname>

This is the quickest way for me, personally:

First delete locally:

git tag --delete <tagname>

Then delete on the remote:

git push --delete origin <tagname>
黄昏下泛黄的笔记 2024-11-04 08:01:49

删除单个标签:

# Local tag example:
git tag -d v1.0.0

# Remote tag example:
git push -d origin v1.0.0

删除多个标签:

# Local tag example:
git tag -d v1.0.0 v1.1.0

# Remote tag example:
git push -d origin v1.0.0 v1.1.0

删除与特定模式匹配的标签:

# Local tag example:
git tag -d $(git tag -l "*beta*")

# Remote tag example:
git push -d origin $(git tag -l "*beta*")

Delete a single tag:

# Local tag example:
git tag -d v1.0.0

# Remote tag example:
git push -d origin v1.0.0

Delete multiple tags:

# Local tag example:
git tag -d v1.0.0 v1.1.0

# Remote tag example:
git push -d origin v1.0.0 v1.1.0

Delete tags that match a particular pattern:

# Local tag example:
git tag -d $(git tag -l "*beta*")

# Remote tag example:
git push -d origin $(git tag -l "*beta*")
渔村楼浪 2024-11-04 08:01:49

删除本地标签“12345”

git tag -d 12345

删除远程标签“12345”(例如 GitHub 版本)

git push origin :refs/tags/12345

替代方法

git push --delete origin tagName
git tag -d tagName

在此处输入图像描述

Delete local tag '12345'

git tag -d 12345

Delete remote tag '12345' (eg; GitHub version too)

git push origin :refs/tags/12345

alternative approach

git push --delete origin tagName
git tag -d tagName

enter image description here

痴情 2024-11-04 08:01:49

请注意,如果您有一个名为远程标记的远程分支,这些命令是不明确的:

git push origin :tagname
git push --delete origin tagname

因此您必须使用此命令来删除标记:

git push origin :refs/tags/<tag>

并使用此命令来删除分支:

git push origin :refs/heads/<branch>

如果没有,您将收到如下错误:

error: dst refspec <tagname> matches more than one.
error: failed to push some refs to '<repo>'

Just notice that, if you have a remote branch named as a remote tag, these commands are ambiguous:

git push origin :tagname
git push --delete origin tagname

So you must use this command to delete the tag:

git push origin :refs/tags/<tag>

and this one to delete the branch:

git push origin :refs/heads/<branch>

If not, you would get an error like this:

error: dst refspec <tagname> matches more than one.
error: failed to push some refs to '<repo>'
七婞 2024-11-04 08:01:49

如果您使用 SourceTree - 一个很棒的 Git GUI - 那么您可以通过执行以下操作轻松地在没有命令行的情况下完成此操作:

  1. 在 SourceTree 中打开您的存储库
  2. 选择并展开左侧的“标签”选项卡
  3. 右键单击​​要删除的标签
  4. 选择“删除 YOUR_TAG_NAME”
  5. 在验证窗口中,选择“从遥控器中删除标签”

YOUR_TAG_NAME 现在将从您的本地存储库和所有遥控器中删除 - 无论是 GitHub、BitBucket 还是您列为遥控器的其他任何地方那个存储库。

此外,如果您在本地删除了标签,但不在远程源上删除了标签,并且想要在所有地方删除它,则只需创建一个具有相同名称并附加在与源相同的提交处的新标签即可。然后,重复上述步骤,将所有地方都删除。

If you use SourceTree - a great Git GUI - then you can easily do this without the command line by doing the following:

  1. Open your repository in SourceTree
  2. Select and expand the "Tags" tab on the left
  3. Right-Click on the tag you want deleted
  4. Select "Delete YOUR_TAG_NAME"
  5. In the verification window, select "Remove Tag From Remotes"

YOUR_TAG_NAME will now be removed from your local repository and all remotes - be it GitHub, BitBucket, or wherever else you listed as a remote for that repository.

Also, if you deleted a tag locally but not on the remote origins, and you want to delete it everywhere, then just create a new tag that has the same name and is attached at the same commit as the origins. Then, repeat the steps above to delete everywhere.

我很坚强 2024-11-04 08:01:49

如果您在 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

If you have created a tag called release01 in a Git repository you would remove it from your repository by doing the following:

git tag -d release01 
git push origin :refs/tags/release01 

To remove one from a Mercurial repository:

hg tag --remove featurefoo

Please reference https://confluence.atlassian.com/pages/viewpage.action?pageId=282175551

愛放△進行李 2024-11-04 08:01:49

针对数千个远程标签的方法速度提高了 100 倍

在阅读这些答案并需要删除超过 11,000 个标签后,我了解到这些方法依赖或 xargs 需要太长时间,除非您有几个小时可以燃烧。

经过一番挣扎,我发现了两种更快的方法。对于这两种情况,请从 git taggit ls-remote --tags 开始,创建要在远程删除的标签列表。在下面的示例中,您可以省略 sorting_proccessing_etc 或将其替换为任何 greping、sorting、tailing 或 < code>head 你想要的(例如 grep -P "my_regex" | sort | head -n -200 etc):


第一种方法是迄今为止最快的,可能比使用 xargs20 到 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 tag -d ,这已经足够了。

git tag | sorting_processing_etc | xargs -L 1 git tag -d

或者类似于远程删除:

git tag -d $(< git tag | sorting_processing_etc | paste -sd " ")

Up to 100x faster method for thousands of remote tags

After reading through these answers while needing to delete over 11,000 tags, I learned these methods relying or xargs take far too long, unless you have hours to burn.

Struggling, I found two much faster ways. For both, start with git tag or git ls-remote --tags to make a list of tags you want to delete on the remote. In the examples below you can omit or replace sorting_proccessing_etc with any greping, sorting, tailing or heading you want (e.g. grep -P "my_regex" | sort | head -n -200 etc) :


This first method is by far the fastest, maybe 20 to 100 times faster than using xargs, and works with a least several thousand tags at a time.

git push origin $(< git tag | sorting_processing_etc \
| sed -e 's/^/:/' | paste -sd " ") #note exclude "<" for zsh

How does this work?
The normal, line-separated list of tags is converted to a single line of space-separated tags, each prepended with : so . . .

tag1   becomes
tag2   ======>  :tag1 :tag2 :tag3
tag3

Using git push with this format tag pushes nothing into each remote ref, erasing it (the normal format for pushing this way is local_ref_path:remote_ref_path).

Method two is broken out as a separate answer elsewhere on this same page


After both of these methods, you'll probably want to delete your local tags too.
This is much faster so we can go back to using xargs and git tag -d, which is sufficient.

git tag | sorting_processing_etc | xargs -L 1 git tag -d

OR similar to the remote delete:

git tag -d $(< git tag | sorting_processing_etc | paste -sd " ")
樱花细雨 2024-11-04 08:01:49

用于从本地和原始位置删除给定标签的简单脚本。
检查标签是否确实存在。

if [ $(git tag -l "$1") ]; then
    git tag --delete  $1
    git push --delete origin $1

    echo done.
else
    echo tag named "$1" was not found
fi

如何使用:

  • 创建shell脚本文件(例如git-tag-purge.sh)并粘贴内容。
  • chmod 您的脚本文件以使其可执行。
  • 使脚本全局可用
  • cd 到您的 git 项目
  • 调用脚本(例如
    gt;git-tag-purge.sh tag_name

Simple script to remove given tag from both local and origin locations.
With a check if tag really exists.

if [ $(git tag -l "$1") ]; then
    git tag --delete  $1
    git push --delete origin $1

    echo done.
else
    echo tag named "$1" was not found
fi

How to use:

  • Create shell script file (e.g. git-tag-purge.sh) and paste content.
  • chmod your script file to make it executable.
  • Make the script globally available
  • cd to your git project
  • Call script (e.g.
    $>git-tag-purge.sh tag_name

    )

枯叶蝶 2024-11-04 08:01:49

更新 2023

首先,从本地存储库中删除标签。
要删除本地 Git 标签,请使用带有 -d 选项的 git tag 命令。

git tag -d <tag_name>

例如,如果您想删除提交列表上名为 v1.0 的本地标记,则可以运行该命令。

git tag -d v1.0

如果删除成功,您可以看到类似以下的输出。

Deleted tag 'v1.0' (was 808b598)

使用 tag 命令和 -l 选项列出现有标签,以确保正确删除标签。

git tag -l

其次,从远程存储库中删除标签。
要删除远程 Git 标签,请使用带有“–delete”选项的“git push”命令并指定标签名称。

git push --delete origin <tag_name>

回到前面的例子,如果你想删除名为“v1.0”的远程 Git 标签,你可以运行。

git push --delete origin v1.0

如果删除成功,您可以看到类似以下的输出。

To https://github.com/SCHKN/repo.git
 - [deleted]         v1.0

要删除远程 Git 标签,请使用 git push 命令并使用 refs 语法指定标签名称。

git push origin :refs/tags/<tag_name>

回到示例,要删除名为 v1.0 的标签,您将运行。

git push origin :refs/tags/v1.0


To https://github.com/SCHKN/repo.git
 - [deleted]         v1.0

为什么我们应该指定refs/tags而不是仅仅指定标签名称?

有时,您的标签可能与您的分支具有相同的名称。

如果您尝试删除 Git 标签而不指定 refs/tags,您将收到以下错误。

git push origin :v1.0


error: dst refspec v1.0 matches more than one.
error: failed to push some refs to '<repository>'

因此,您需要指定您正在尝试删除 Git 标签而不是 Git 存储库。

Update 2023

First, delete a tag from the local repository.
To delete a local Git tag, use the git tag command with the -d option.

git tag -d <tag_name>

For example, you would run if you wanted to delete a local tag named v1.0 on your commit list.

git tag -d v1.0

If deleting is successful, you can see something like this output.

Deleted tag 'v1.0' (was 808b598)

List your existing tags using the tag command and the -l option to ensure that tags were correctly deleted.

git tag -l

Second, delete the tag from the remote repository.
To delete a remote Git tag, use the “git push” command with the “–delete” option and specify the tag name.

git push --delete origin <tag_name>

Back to the previous example, if you want to delete the remote Git tag named “v1.0”, you would run.

git push --delete origin v1.0

If deleting is successful, you can see something like this output.

To https://github.com/SCHKN/repo.git
 - [deleted]         v1.0

To delete a remote Git tag, use the git push command and specify the tag name using the refs syntax.

git push origin :refs/tags/<tag_name>

Back to the example, to delete a tag named v1.0, you would run.

git push origin :refs/tags/v1.0


To https://github.com/SCHKN/repo.git
 - [deleted]         v1.0

Why should we specify the refs/tags instead of just specifying the tag name?

Sometimes, your tag may have the same name as your branch.

If you tried to delete your Git tag without specifying the refs/tags you would get the following error.

git push origin :v1.0


error: dst refspec v1.0 matches more than one.
error: failed to push some refs to '<repository>'

Consequently, you need to specify that you are trying to delete a Git tag and not a Git repository.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文