David Callanan
David Callanan

Reputation: 5968

Git update tag without creating new branch?

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?

Upvotes: 0

Views: 1974

Answers (2)

David Callanan
David Callanan

Reputation: 5968

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

Upvotes: 0

Shaqil Ismail
Shaqil Ismail

Reputation: 1961

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.

Upvotes: 1

Related Questions