You can add tags with the "git tag" command. Tags are a feature that allows you to name one of a particular commit. It is used when you want to give a version name or remember a specific commit position.
Add a tag name to the beginning of the current commit
Let's give the current commit a tag name. The tag name is "foo".
#Tag git tag foo
Specify the commit ID and give it a tag name
You can also specify the commit ID and give it a tag name.
#Tag git tag foo commit ID
If you want to find out the commit ID, use the " git log" command.
Display a list of tags
To see a list of tags, run the "git tag" command with no arguments.
#Display a list of tags git tag
This is a sample output result.
v1.0 v1.2 20210816
Reflect tags in remote repository
To reflect the tag in the remote repository, use the " git push" command and set it to "git push remote branch name tag name".
Reflect # tag in remote repository git push origin v1.0
Reflect all tags in remote repository
To apply all tags to the remote repository, use the "--tags" option with the git push command.
# Reflect all tags in remote repository git tag origin --tags
Add version number
Let's add a version number with the "git tag" command.
git tag v1.0
Use the date as the tag name and memorize it
A common technique is to tag the current date to remember the commit at that time. In Git, it's common to find mistakes after a merge and wonder how to get back to what they were before the merge.
In such a case, it is convenient to use the date and give a tag name in advance so that you can return to that state.
# Use date as tag name git tag 20210816
If you want to return to the previous state, use the git reset command and set it to "git reset --hard tag name". (Be careful when using "git reset --hard" in the "git reset" command.)
git reset --hard 20210816