How can I move a tag on a git branch to a different commit?

5.1K    Asked by ashish_1000 in Business Analyst , Asked on May 3, 2021

 I created a tag on the master branch called v0.1 like this:

git tag -a v0.1

But then I realized there were still some changes I needed to merge into master for release 0.1, so I did that. But now my v0.1 tag is stuck on (to invoke the post-it note analogy) the wrong commit. I want it to be stuck on the most recent commit on master, but instead, it is stuck on the second most recent commit on master.

How can I move it to the most recent commit on master? How git move tag ?

 

Answered by Behailu

 For Updating an existing tag use the following command

git tag -a -f v1.4

Executing the above command will map the commit to the v1.4 tag identifier. It will override any existing content for the v1.4 tag.

-f option must be used to move a tag on a git branch to a different commit.

Or You can follow the below steps:

Delete the tag on any remote before you push git push origin :refs/tags/

Replace the tag to reference the most recent commit git tag -fa

Push the tag to the remote origin git push origin master--tags.



Your Answer

Interviews

Parent Categories