How do you revert to a specific tag in Git? How do you revert to a specific tag in Git? git git

How do you revert to a specific tag in Git?


Git tags are just pointers to the commit. So you use them the same way as you do HEAD, branch names or commit sha hashes. You can use tags with any git command that accepts commit/revision arguments. You can try it with git rev-parse tagname to display the commit it points to.

In your case you have at least these two alternatives:

  1. Reset the current branch to specific tag:

    git reset --hard tagname
  2. Generate revert commit on top to get you to the state of the tag:

    git revert tag

This might introduce some conflicts if you have merge commits though.


Use git reset:

git reset --hard "Version 1.0 Revision 1.5"

(assuming that the specified string is the tag).


You can use git checkout.

I tried the accepted solution but got an error, warning: refname '<tagname>' is ambiguous'

But as the answer states, tags do behave like a pointer to a commit, so as you would with a commit hash, you can just checkout the tag. The only difference is you preface it with tags/:

git checkout tags/<tagname>