Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git tags are showing even though I deleted them

Tags:

git

I have deleted some tags by running:

  1. git tag -d TAGNAME
  2. git push origin :refs/tags/TAGNAME

After that I asked all team members to run:

  1. git tag -d $(git tag) - to remove all local tags
  2. git fetch --tags - to retrieve current tags from remote.

The problem is that now and then I see the old tags appearing again. I suspect that someone still has a few old tags and didn't delete them or pulled before I deleted or so.

Is there a way to completely delete a tag?

For example - to make a commit that deletes old tags and so before users will be able to push they will have to pull that commit and so it will change their tags. Is that possible?

like image 860
Ariel Einfeld Avatar asked Jul 30 '15 13:07

Ariel Einfeld


People also ask

Can git tags be deleted?

Use Git to delete a Git tag To delete the Git tag from the local repo, run the git tag -d tag-name command where tag-name is the name of the Git tag you want to delete.

How do I remove tags from GitHub?

To fetch tags from your remote repository, use “git fetch” with the “–all” and the “–tags” options. Let's say for example that you have a tag named “v1. 0” that you want to check out in a branch named “release”. Using this command, you have successfully checked out the “v1.

Does deleting a git tag delete the commit?

You do not remove commits. You remove pointers to commits and if commits are no longer referenced git will garbage collect them some day (depending on your configuration).

What happens when you delete a tag in git?

Delete a local Git tag If you try to delete a Git tag that does not exist, you will simply be notified that the tag does not exist. $ git tag -d v2. 0 error: tag 'v2. 0' not found.


2 Answers

When you delete remote branches, you have to git remote prune origin in order to completely remove these deleted branches from the working copy.

Since tags are quite much the same as branches, I assume you need to prune here too.

git fetch also knows the --prune parameter, so either

git remote prune origin

or

git fetch --prune

should do the trick.

This is an additional safety measure: fetch only updates known remote branches and introduces new ones but never deletes them unless --prune is requested.

like image 183
eckes Avatar answered Sep 22 '22 07:09

eckes


The solution from @eckes did not work for me; what did work was this answer from Joseph K Strauss:

https://stackoverflow.com/a/30782368/15382340

git fetch origin refs/tags/*:refs/tags/* --prune
like image 22
nicensee Avatar answered Sep 23 '22 07:09

nicensee