user1977981
user1977981

Reputation: 189

How do I undo a local deletion of a tag on github?

I deleted a tag on my repo with the command

git tag -d v1.1

I misunderstood what this would do and thought it would just remove the tag annotation. Instead it rolls it back to where that tag was added which was quite a few commits a go. I didn't realise this and I then re-tagged it thinking I was at the most current commit

git tag -a v1.1 -m "Merged development branch back into master branch."

Now my repo is rolled back to when that original tag was added and I am not sure how to undo this. I have not pushed anything so my remote repo is unaffected. What is the most appropriate way to undo this change?

Upvotes: 1

Views: 5327

Answers (3)

friederbluemle
friederbluemle

Reputation: 37147

If you just deleted the tag (and the terminal scrollback is still available), you should see a message similar to the following:

$ git tag -d v1.1
Deleted tag 'v1.1' (was c4f3b4b3)

Run the following command to restore the tag:

git update-ref refs/tags/v1.1 c4f3b4b3

Upvotes: 5

AlexGongadze
AlexGongadze

Reputation: 379

If you have your deleted tag at the remote repo and you are here just looking for the answer to this question:

How do I undo a local deletion of a tag on github?

Simply do:

git pull

and it will return the deleted tag to your local list of tags.

Upvotes: 1

CodeWizard
CodeWizard

Reputation: 142412

Use the git reflog.
A full detailed answer is found here but ill summary it for you,

How to move HEAD back to a previous location? (Detached head)


git reflog

git reflog will display any change which updated the HEAD and checking out the desired reflog entry will set the HEAD back to this commit.

Every time the HEAD is modified there will be a new entry in the reflog

In your case you need to find out the last commit before removing the tag and check it out, then read the attached answer on how to continue from there.

git reflog
git checkout HEAD@{...}

This will get you back to your desired commit

enter image description here


Upvotes: 2

Related Questions