Git tag
Тег в Git
A named reference in a Git repository that usually points to a specific commit. Teams use tags such as `v1.4.0` to find the source code for a release after development has moved on.
Also known as: git tag
What a Git tag is for
Suppose a customer reports a bug in version 1.4.0. The tip of main may contain weeks of changes that never shipped in that version. If the team tagged the release commit as v1.4.0, you can use that name to inspect the code the release was built from. A branch tip moves as commits are added to the branch; a tag does not move when you make a commit.
What Git stores
Tag references live under refs/tags/. A tag usually identifies a commit, but it can point to other Git objects. Git supports two kinds of tags:
- A lightweight tag is a reference directly to an existing object.
git tag local-testpoints the name at the current commit without creating a separate tag object. - An annotated tag points to a tag object, which records the target, the tagger's name and email, a timestamp, and a message. It can also carry a cryptographic signature that others can verify. Annotated tags are a common choice for published releases because they can record who marked the release and why.
Git does not enforce a versioning scheme. The v prefix and the version number are project conventions, not requirements for a tag name.
Tag and publish a release
First check that the current commit is the one you intend to ship. Then run:
git tag -a v1.4.0 -m "Release 1.4.0"
git show v1.4.0
git push origin tag v1.4.0
The first command creates an annotated tag locally. To tag an older commit instead, add its hash at the end of that command. Use git show to inspect the tag and its target before pushing. The last command publishes just that tag to the remote named origin. Pushing a branch does not normally publish its tags; git push origin --tags pushes all local tags, including any you meant to keep private.
Common mistakes
A tag identifies source code; it does not build a package or deploy it. A CI/CD pipeline can react to a tag push, and a hosting service can associate release notes and downloadable files with a tag. Those are separate from the tag itself. To see the net source changes between two tagged versions, use git diff v1.3.0 v1.4.0.
Treat published release tags as fixed even though Git lets you delete or force-update them. Moving a published tag can leave two developers with the same tag name pointing to different commits. If the release needs a fix, publish a new version under a new tag rather than silently moving the old one.
In an interview
You may be asked whether you can start work from a tag. Yes: git switch -c fix-1.4 v1.4.0 creates a branch at the tagged commit, leaving the tag unchanged. By contrast, git switch --detach v1.4.0 puts you in detached HEAD state: you can inspect or build that version without switching to a branch, but new commits will not advance any branch.