As explained in this old thread, git does not provide a way to move tags between commits during amend or rebase.
The provided git-rebase-autotags.py script is a simple post-rewrite git hook which will be called after a commit has been
modified by git amend or rebase command to move tags from old commit to new one.
You can easily install this hook in your git repository following these steps:
- Copy
git-rebase-autotags.pyinside.git/hooksdirectory of your repository - Rename
git-rebase-autotags.pyaspost-rewritein order to be automatically executed by git - Make sure the hook is executable
chmod a+x .git/hooks/post-rewriteYou can use the git template functionnality to provide git-rebase-autotags hooks accross all your repositories.
- Configure git templates
git config --global init.templatedir '~/.git-templates'
mkdir -p ~/.git-templates/hooks
-
Copy
git-rebase-autotags.pyinside~/.git-templates/hooksdirectory -
Rename
git-rebase-autotags.pyaspost-rewrite -
Make sure the hook is executable
chmod a+x ~/.git-templates/hooks/post-rewrite- Re-initialize git in each existing repo you'd like to use this in
git initWARNING: if you already have a hook defined in your local git repo, this will not overwrite it.
The autotags functionnality is disabled by default. You can easily enable it adding rewrite.autotags.enabled = true
in your local or global configuration.
git config [--global] --add rewrite.autotags.enabled trueIt is recommended to enable git push.followTags feature which will prevent you to have to separately call git push --tags to push
your tags.
git config --global push.followTags true