Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I commit to an old git tag?

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?

like image 895
Jon Ursenbach Avatar asked Nov 11 '10 02:11

Jon Ursenbach


People also ask

Can you commit to a 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.

Can you reuse a git tag?

Git tags can't be reused. A tag can be removed and reassigned.

How do I make an old commit new head?

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).


2 Answers

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.

like image 198
toobulkeh Avatar answered Sep 25 '22 04:09

toobulkeh


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.

like image 22
cdhowie Avatar answered Sep 22 '22 04:09

cdhowie