Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tag an older commit in Git?

We are new to git, and I want to set a tag at the beginning of our repository. Our production code is the same as the beginning repository, but we've made commits since then. A tag at the beginning would allow us to "roll back" production to a known, stable state.

So how to add a tag to an arbitrary, older commit?

like image 594
hogsolo Avatar asked Dec 09 '10 23:12

hogsolo


People also ask

How do I find old commits?

To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.

Does git tag also commit?

Git supports two types of tags: lightweight and annotated. A lightweight tag is very much like a branch that doesn't change — it's just a pointer to a specific commit. Annotated tags, however, are stored as full objects in the Git database.


1 Answers

Example:

git tag -a v1.2 9fceb02 -m "Message here" 

Where 9fceb02 is the beginning part of the commit id.

You can then push the tag using git push origin v1.2.

You can do git log to show all the commit id's in your current branch.

There is also a good chapter on tagging in the Pro Git book.

Warning: This creates tags with the current date (and that value is what will show on a GitHub releases page, for example). If you want the tag to be dated with the commit date, please look at another answer.

like image 64
dkinzer Avatar answered Sep 21 '22 13:09

dkinzer