I have some old tags in my git repository that are no longer important. I would like to archive the tags so that they don't show up by default when running git tag. I don't want to delete them, because I want to keep the history. How can I do this?
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. To get a list of Git tag names, run git tag.
Git tags can't be reused. A tag can be removed and reassigned.
It's possible to keep the tags in the repo and avoid listing them as tags. It also avoids default clones from fetching them.
In origin (the bare repo) assuming you want to archive all tags starting with 'HIDE':
mkdir refs/archive
mv refs/tags/HIDE* refs/archive/
Now git tag
will no longer list these refs, however they will still exist in the repository.
If you later want to pull down the archived tags to your local clone you can run the following:
git fetch origin +refs/archive/*:refs/archive/*
You can now list them using:
git for-each-ref refs/archive
You should be careful when you delete tags. Maybe a tag is the only reference to some sommit.
branch
|
V
o---o---o----o---o---o
\
o---o---o---o
^
|
someTag
If you remove the last reference to a commit you will loose the commit someday. Someday means as soon as git gc
collects them.
If you don't have this problems you can use
$ git show-ref --tags > tag_refs-20141126.txt
to dump your tags and the commit ids to to a file. Then commit this file to your repository or keep it somewhere else. After this you can delete the tags
$ git for-each-ref --format="%(refname)" refs/tags | cut -c11- | \
while read tag; do git tag -d $tag; done
and restore them later
$ cat tag_refs-20141126.txt | while read commitid tagref; do echo $tagref $commitid; done \
| cut -c11- | while read tagname commitid; do git tag $tagname $commitid; done
EDIT
I would prefer Dan Fabulich or Zitrax's answer. Using hidden refs is what I also do. E.g. when I want to backup stashes. I wrote a git extension for that some time ago.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With