How do you revert to a specific tag in Git?

zachd1_618 picture zachd1_618 · Aug 20, 2013 · Viewed 97.6k times · Source

I know how to revert to older commits in a Git branch, but how do I revert back to a branch's state dictated by a tag? I envision something like this:

git revert -bytag "Version 1.0 Revision 1.5"

Is this possible?

Answer

jurglic picture jurglic · Aug 21, 2013

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.