Why this matters
A version number is a promise: 2.1.0 means the same code for everyone, forever. Composer finds that code through a Git tag, and on most hosts a tag can be moved to a different commit at any time.
When a tag moves, people who installed the version before and people who install it after get different code under the same number. Lock files that recorded the old commit stop matching, mirrors and caches disagree, and anyone who reviewed the release reviewed something that no longer exists. Moving a tag is also exactly how an attacker with a stolen maintainer account would change a trusted release without anyone noticing.
What good looks like
- A version tag, once published, never changes.
- A broken release is fixed by publishing a new version, such as
2.1.1, never by moving2.1.0. - Release scripts never force-push tags.
How to do it
Release again instead of re-tagging
If you tagged the wrong commit or forgot a file, leave the tag alone and publish the next patch version. It costs a version number and nothing else. Note the problem in the release notes if it helps your users.
Remove force pushes from your tooling
Search your release scripts, Makefiles, and CI workflows for git tag -f, git tag --force, git push --force --tags, and git push -f origin <tag>, and remove them.
Lock tags where your host allows it
- GitHub: turn on immutable releases in Settings, General, Releases, and publish every version as a release. Its tag can then never be moved.
- GitHub: a tag ruleset that restricts updates and deletions blocks moves for tags without a release.
- GitLab: add a protected tag rule, such as
v*, under Settings, Repository, Protected tags.
Things to watch for
- Retried release jobs. Some release tools delete and recreate the tag when a job is retried. Make retries publish a new version instead.
- If a tag was moved anyway. Point it back at the commit it was originally released from as soon as you can, so new installs get the code people reviewed. If you did not move it yourself, treat it as a compromised account: revoke tokens and keys, check recent pushes, and tell your users which versions were affected. Publish any fix as a new version.
- Mirrors. If your repository is mirrored from another host, a moved tag at the source is pushed to the mirror. Lock tags where releases are created.
- Deleting and recreating. Deleting a tag and pushing a new one with the same name moves it just the same.