How can I commit to an old git tag?
Solution 1
Tags are not movable. Once you have created a tag that points to a particular commit, you cannot change that tag later.
It sounds like you meant to create a branch instead. You should create a new branch (git branch branchname && git checkout branchname
) to make sure you don't lose your commits. Then push that branch to the repository and have your release/bugfixing developers work in that branch for the release.
Solution 2
If someone is coming here after searching for "replace git tag" or something similar, I recommend the following approach:
git tag -d <tagname>
git checkout <new commit or branch>
git tag -a <tagname>
git push <remotename> <tagname> -f
for example:
git checkout 2.0
git tag -d v2.0
git tag -a v2.0 -m"Version 2.0"
git push origin v2.0 -f
Hope this helps someone.
Solution 3
You mean branch, not tag. Tags in Git are point-in-time bookmarks in your master branch. While you CAN overwrite a tag (git tag -f
), it is not recommended. I will ONLY overwrite a tag if it has not been deployed yet.
Solution 4
If user is using same branch from which user created the old tag then first create new changelist. otherwise checkout the tag and then create new changelist. then use below steps to update existing tag with new changelist number
git tag -f <old tag name>
git push -f --tags
Total 0 (delta 0), reused 0 (delta 0)
+ ... <old tag name>
-> <old tag name>
(forced update)
Solution 5
You should create a new branch at the position of the tag, delete the tag, make your commits, recreate the tag and push.
Jon Ursenbach
Updated on February 18, 2020Comments
-
Jon Ursenbach about 4 years
So two months ago I migrated our codebase in SVN into Git with the complete changeset history. Immediately after that, we tagged a new release and continued working. So while we've continued working in the new tag, some people have continued fixing bugs in the old tag in SVN and now I'd like to pull all those changes into that tag in Git.
I can clone the tag and make Git will let me make commits into it, but I can't push anything back up with git-push. Checking git-log, the commit is there but git-st tells me that I'm not currently on any branch.
So Internet, how can I commit to an old git tag?
-
Jon Ursenbach over 13 yearsA combination of branching and overriding old tags is what I was looking for since this is tag is mirrored code from our SVN repo.
-
cdhowie over 13 yearsUnfortunately, you can't really override old tags. But you can abandon them. :)
-
Jon Ursenbach over 13 yearsYeah that's what I'm ending up doing. Such a pain in the ass to get all these old commits back in. Thanks for the help!
-
cdhowie over 13 yearsOh, by abandon them I meant just forget about them... are you actually rebuilding the repo from SVN without them?
-
ThomasW about 12 yearsHere's a working link to the git tag page: schacon.github.com/git/git-tag.html
-
Fran Martinez over 8 yearsthe last command can also be: git push <remote_name> <tag_name> -f e.g. git push origin v2.0 -f
-
linehrr over 6 yearstags are removable, you can do: git tag -d <tag>, but on the remote, you have to remove it too before you can do another tag sync: git push origin --tags
-
cdhowie over 6 years@linehrr This is not advisable once a tag has been pushed; anyone who has cloned the repository will be very sad when they try to fetch.