Moving a tag in Git

Defeats the object of versioning but sometimes you've just got to do it!

Its very rare a tag should be moved but sometimes you just have to do it.  In my scenario I had tagged and released version v1_3_0 of this site, all good and dandy.  At a later date when I needed to deploy a bug release (v1_3_1) I checked out the tagged version an noticed the version in the pom.xml was incorrect, it was actually v1_2_0.

I applied the bug fix and relased version v1_3_1 but I wasn't happy that the tagged version v1_3_0 had the wrong version tagged in the pom.xml, something had to be done!  Here is how I fixed it:

%> git checkout Version_1_3_0

Make the required changes, in my case update pom.xml, update version line with <version>1.3.0</version> then go ahead and move the existing tag with the commands below, to move the tag you first need to add your change to the index and commit, then tag the current code base with -f (force) -a (annotated tag) and finally push the tag, like below:

%> git add pom.xml
%> git commit -m "Corrected version number"
%> git tag -f -a Version_1_3_0
%> git push -f --tags (this will push all tags, optionally you can name the tag with --tag <tagname>
 
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 1.74 KiB | 1.74 MiB/s, done.
Total 4 (delta 0), reused 0 (delta 0)
 + d6257e3...3365248 Version_1_3_0 -> Version_1_3_0 (forced update)

There we have it, correct version alongside the tag v_1_3_0

Tags:
git

v1.9.1

© ScottFreeIT.com 2020