Title: In git, how can I undo the local deletion of an annotated tag that has not been pushed?
Tags: git;git-tag
Question: I accidentally deleted an annotated tag locally that I did not intend to delete.  I have not yet pushed the tag's deletion to the remote.  I would like to undo this mistake.
```$ git tag -n999
v1.0.0          Initial release

$ git tag -d v1.0.0
Deleted tag 'v1.0.0' (was 1a2b3c4)
```
I've searched online and here on Stack Overflow in an attempt to find a solution.  Despite the seeming straightforward nature of this action, I have not had any luck finding a solution.
How can I undo the local tag deletion, reverting the tag to the state it was before I deleted it?


Here is the accepted answer: FYI, I've never done this before prior to answering this question.
But after googling your question, I found this article:
https://dzone.com/articles/git-tip-restore-deleted-tag
I tested its advice, and it worked for me.

In summary:
Use this to get the list of annotated tag objects that have been removed:
```git fsck --unreachable | grep tag

# if don't have grep because you're on windows, you can use this:
git fsck --unreachable | sls tag
```
Use this to examine the findings from the previous command:
```git show KEY
```
Use this to restore the tag:
```git update-ref refs/tags/NAME KEY
```


Here is another answer: ```
```$ git tag -d v1.0.0
Deleted tag 'v1.0.0' (was 1a2b3c4)
$
```
```
That deleted the local ref ```refs/tags/v1.0.0```. To put it back,
```git tag v1.0.0 1a2b3c4
```
That's why the deletion mentioned the object id in the db. Git won't clean objects out of the db until they've been unreachable through any ref for two weeks or more (say ```git help config``` and search for gc.*expire), specifically so it doesn't snatch things out from under in-flight operations and ordinary mistakes and second thoughts. You can hang a ref on any object.

Comment for this answer: The annotated tag is an object. If you don't have a refname for it, then you don't have a refname for it. If you do, then you do. `git tag -d` removes the refname. `git tag` puts it back. Only repack and prune (and the convenience commands that invoke them, like gc)  removes objects from the object db, deleting a refname does absolutely nothing to the object db.
Comment for this answer: That's it. You fetch or create tag objects, git automatically makes (ordinary) `refs/tags` refs for them. That's the entirety of the special treatment for them.
Comment for this answer: This looks to be a good way to restore a non-annotated tag, assuming you still have the deleted hash available.  It wouldn't restore an annotated tag with message, etc., however.
Comment for this answer: Looks like I stand corrected.  It I am inferring correctly, the hash returned on deletion is the reference to the tag object.  Calling `git tag` (without `-a`) creates a lightweight tag (i.e. just a pointer) pointing at the tag object.  Since that's a pointer to a tag object, the end result is the same as creating an annotated tag: a named pointer to a tag object, and thus it's a full-fledge annotated tag.  This a correct analysis?

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:12/12/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<git><git-tag>', 'Title': 'In git, how can I undo the local deletion of an annotated tag that has not been pushed?', 'ViewCount': 142, 'id': 65260284, 'user_AboutMe': '<p>I am a professional software developer with over a decade of experience with Java, Spring, and numerous other technologies.</p>\n', 'user_AccountId': 1119690.0, 'user_DisplayName': 'M. Justin', 'user_Reputation': 10554.0, 'user_Views': 611.0, 'user_id': 1108305.0}}