Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-tag

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?

like image 914
eedeep Avatar asked Nov 08 '11 00:11

eedeep


People also ask

Can tags be moved git?

We can move tags in Git by introducing the --force option to the git tag command.


1 Answers

Use the -f option to git tag:

-f --force      Replace an existing tag with the given name (instead of failing) 

You probably want to use -f in conjunction with -a to force-create an annotated tag instead of a non-annotated one.

Example

  1. Delete the tag on any remote before you push

    git push origin :refs/tags/<tagname> 
  2. Replace the tag to reference the most recent commit

    git tag -fa <tagname> 
  3. Push the tag to the remote origin

    git push origin master --tags 
like image 125
Greg Hewgill Avatar answered Sep 23 '22 11:09

Greg Hewgill