Git Checkout Tag
You can checkout a tag in a git repo by usingThis is pretty useful for exploring historical version of code bases. “What was this codebase like at release X?” I needed this in order to find a removed function in Erlang.:
$ git checkout <tag>
Simple as that.
Note that running this command without a branch will put you in “detached HEAD” state, meaning that any commits you make will be reachable only by their exact hash. If you want to make changes with a tag as your starting point, use
-b <branch name> like this:
$ git checkout -b <branch name> <tag>
Read more in the git documentation.
When I initially looked up how to do this,
I found instructions to use
git checkout tags/<tag>.
This is contrary to git’s own documentation, but it worked!
This seems to work because tags are a ref in the
and git correctly identifies the right tag, and thus the right commit from there.
I believe this is the same mechanism as when you give a short hash and git finds the correct commit.