0

I have a tag v1 set to an old commit. There is a bug with this version and I'd like to update it.

I ran get checkout v1. I have updated the code to fix this bug, then git-added and git-commited.

Now I would like to update the tag v1 to reference this new commit.

I tried git push -f origin v1. This does not work. I get the following response:

Everything up-to-date

Is there a way of achieving this? Preferably, I'd like to avoid creating a new branch, but if I have to, how can I avoid polluting the branch namespace? Can I just delete the branch afterwards?

David Callanan
  • 5,601
  • 7
  • 63
  • 105
  • 1
    You can't "update a tag", you have to delete the existing tag and apply the same tag to the new commit. – jonrsharpe Jul 30 '21 at 11:12
  • Does this answer your question? [How can I move a tag on a git branch to a different commit?](https://stackoverflow.com/questions/8044583/how-can-i-move-a-tag-on-a-git-branch-to-a-different-commit) – Gaël J Jul 30 '21 at 11:27
  • I didn't realize you could create a commit and then the new tag would reference that commit. I thought you had to first push to a new branch. So I think I got a solution – David Callanan Jul 30 '21 at 13:17
  • You *can* move a tag. You *should not* move a tag, because other people who have cloned your repository may *assume* that the tag has not moved, and may either ignore your moving of the tag, or actively fight you over it. It's generally a bad idea. In special circumstances, it's not actively harmful or even helpful, just as it's sometimes okay to cut off your hand (e.g., when gangrene has set in). But be careful with this. – torek Jul 31 '21 at 01:13

2 Answers2

1

A tag is usually used for seeing the files at a specific version and the files is not meant to be changed once it is tagged, for example version 1.0 if you want to make changes and retag afterwards,

  1. Create a new branch for example branch a, from the tag you would like to update.
  2. create your commits on the the new branch a.
  3. When you are ready to replace the tag with the branch a, delete the tag where you created branch a from.
  4. create your new tag from branch a
  5. If you should remove the branch a afterwards, then delete branch a.
Shaqil Ismail
  • 1,794
  • 1
  • 4
  • 5
  • Everything about branch `a` here is irrelevant. Why such a complex process, just to delete a tag and recreate it on another commit? Your answer is not *wrong* but... I don't see how it adresses the question. – Romain Valeri Jul 30 '21 at 12:21
0

I finally came up with a solution that works that doesn't require the creation of a new branch.

  1. git checkout tag_name

  2. Make local changes

  3. git add . and git commit -m "commit message"

  4. git tag -fa tag_name

  5. git push -f origin master --tags

David Callanan
  • 5,601
  • 7
  • 63
  • 105