Git tag = etiqueta permanente num commit específico.
Uso principal: marcar as versões (v1.0, v2.0, etc.)
Diferença em relação às branches:
Analogia: Tag = autocolante « Versão 1.0 » numa página do caderno.
git tag v1.0 # Tag simplesgit tag -a v1.0 -m "Version 1.0 - First stable release"mkdir demo-tags && cd demo-tags
git init
echo "print('app v0.1')" > app.py
git add . && git commit -m "Initial version"
echo "print('app v0.2')" > app.py
git add . && git commit -m "Bug fixes"
echo "print('app v1.0')" > app.py
git add . && git commit -m "First stable version"# Tag simples
git tag v1.0
# Tag com mensagem
git tag -a v1.0-stable -m "Version 1.0 - Production ready"
# Tag num commit anterior
git log --oneline # Ver os hashes
git tag v0.2-beta <hash> # Tag num commit específicogit tag # Todas as tags
git tag -l "v1.*" # Tags que correspondem ao padrão
git show v1.0 # Detalhes da taggit checkout v1.0 # Ir ao commit etiquetado
git checkout main # Voltar a maingit push origin v1.0 # Push de uma tag específica
git push origin --tags # Push de todas as tagsvMAJOR.MINOR.PATCH
- v1.0.0 → First stable release
- v1.0.1 → Bug fix
- v1.1.0 → New feature (backward compatible)
- v2.0.0 → Breaking changes# Desenvolvimento concluído
git checkout main
git pull origin main
# Tag de release
git tag -a v1.2.0 -m "Release v1.2.0 - Add user authentication"
# Push do código + tags
git push origin main
git push origin v1.2.0
# Ou push tudo de uma vez:
git push origin main --tags# Apagar tag local
git tag -d v1.0
# Apagar tag remota
git push origin --delete v1.0
# Modificar uma tag (recriar)
git tag -d v1.0 # Apagar local
git push origin --delete v1.0 # Apagar remoto
git tag -a v1.0 -m "Corrected message" # Recriar
git push origin v1.0 # Voltar a enviar1. Release em produção:
git tag -a v2.1.0 -m "Production release v2.1.0"
git push origin v2.1.0
# Implantar a versão v2.1.0 em produção2. Voltar a uma versão anterior:
git checkout v2.0.0 # Voltar à versão estável
git checkout -b hotfix-v2.0.0 # Criar branch hotfix3. Comparar versões:
git diff v1.0.0 v2.0.0 # Ver todas as alteraçõesTags = marcos permanentes do seu projeto. Use-as em todas as releases!