# git tag: name a commit, lightweight and annotated

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/git-tag-full-en
A tag is a name for an object, usually a commit; lightweight tags point at the commit, annotated tags are their own objects.

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

(Test: 3 tests were run, TE-15-A, TE-15-B and TE-15-C. The expected non-zero exit is TE-15-C (exit status 128). Every row has a recorded log in the evidence archive. The evidence table lists the exit status and log hash of every row, and no Exit status line on this page is for the A row.)

### TE-15-A: lightweight tag points at a commit, an annotated tag is its own object, and a tag can be moved with -f

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one; git rev-parse HEAD > ../c1.sha
printf 'two\n' >> f.txt; git add f.txt; git commit -qm two; git rev-parse HEAD > ../c2.sha
```

Paths written as `../name` sit one level above the repository folder, inside the same throwaway tree, so they do not appear in `git status`.

Command:

```bash
git tag light $(cat ../c1.sha); git tag -a ann -m msg $(cat ../c1.sha); git tag -f light $(cat ../c2.sha) >/dev/null; echo tagged=$?
```

Recorded output:

```
tagged=0
```

Check command and its recorded output:

```bash
echo light_type=$(git cat-file -t light); echo ann_type=$(git cat-file -t ann); echo moved=$([ "$(git rev-parse light)" = "$(cat ../c2.sha)" ] && echo yes)
```

```
light_type=commit
ann_type=tag
moved=yes
```

### TE-15-B: git tag -l with a pattern lists only the matching tag names

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
git tag v1.0; git tag v1.1; git tag v2.0
```

Command:

```bash
git tag -l 'v1*'
```

Recorded output:

```
v1.0
v1.1
```

Exit status: 0. This status and the output match what was written before the run.

### TE-15-C: expected non-zero exit: creating a tag whose name already exists is refused

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
git tag v1
```

Command:

```bash
git tag v1
```

Recorded output: none, standard output was empty.

Standard error from the same run:

```
fatal: tag 'v1' already exists
```

Exit status: 128. This status and the output match what was written before the run.

## Reading the recorded output

The line tagged=0 is the exit status of the last tag command in the run, the forced move of light. The check lines then show that light is a commit object, so a lightweight tag here is only a name for a commit, while ann is a tag object of its own. The line moved=yes shows that after git tag -f pointed light at the second commit, light resolved to the id of that second commit.

TE-15-B: by the setup, the tags are v1.0, v1.1 and v2.0. git tag -l 'v1*' printed v1.0 and v1.1. TE-15-C: by the setup, the tag v1 already existed. git tag v1 exited with status 128 and printed fatal: tag 'v1' already exists.

## Limits

Tags can be moved with `-f` and deleted with `-d`; they do not follow new commits.

## Source

- https://git-scm.com/docs/git-tag

## Evidence

- `TE-15-A`: lightweight tag points at a commit, an annotated tag is its own object, and a tag can be moved with -f

- logs: one recorded log for each row above
- Recorded on: Linux x86_64, kernel 7.3.4; bash 5.1.16; git 2.34.1; python 3.10.12; findutils 4.8.0; grep 3.7; sed 4.8; gawk 5.1.0; tar 1.34; curl 7.81.0. Locale C.UTF-8, TZ=UTC.

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-15-A` | lightweight tag points at a commit, an annotated tag is its own object, and a tag can be moved with -f | 0 | PASS | `79aa78d64b65` |
| `TE-15-B` | git tag -l with a pattern lists only the matching tag names | 0 | PASS | `882079ab431a` |
| `TE-15-C` | expected non-zero exit: creating a tag whose name already exists is refused | 128 | PASS | `ff76d3bb3d06` |

Every row has a recorded log holding the setup commands, the command, stdout, stderr, exit status and the final directory state. The first 12 characters of the log's sha256 are in the table.

## Related guides
- [git remote: connect a repository to another one](https://kairos-2z6s.onrender.com/res/git-remote-full-en)
- [git clean: delete untracked files, with a dry run first](https://kairos-2z6s.onrender.com/res/git-clean-full-en)
- [Everyday Git: branches, stash, undo and merge conflicts](https://kairos-2z6s.onrender.com/res/git-workflows-hub-en)
- [Git Switch: change branches](https://kairos-2z6s.onrender.com/res/git-switch-full-en)
- [Git still tracks .env after adding it to .gitignore](https://kairos-2z6s.onrender.com/res/gitignore-env-not-ignored-en)
- [Git Stash Include Untracked: set aside new files too](https://kairos-2z6s.onrender.com/res/git-stash-include-untracked-full-en)
- [Git Restore: unstage or discard a file](https://kairos-2z6s.onrender.com/res/git-restore-full-en)
