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?
You can't put a new commit into an existing tag without breaking an important Git guideline: Never(*) modify commits that you have published. Tags in Git aren't meant to be mutable. Once you push a tag out there, leave it alone.
Git tags can't be reused. A tag can be removed and reassigned.
To hard reset files to HEAD on Git, use the “git reset” command with the “–hard” option and specify the HEAD. The purpose of the “git reset” command is to move the current HEAD to the commit specified (in this case, the HEAD itself, one commit before HEAD and so on).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With