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?
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.
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.
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)
If I'm understanding your problem correctly, you need to create a branch where your commits are. To do this, check out the version you want to push up. In your git bash, type in:
git branch old-version
This should create a branch at the location of your commit called old-version
. Then try pushing.
You should create a new branch at the position of the tag, delete the tag, make your commits, recreate the tag and push.
There's a number of things going on here.
It sounds like you don't have an adequate understanding of the purpose of git tag. I'd recommend reading that man page and also the relevant section of Pro Git. Pro Git also makes an excellent introduction in general to the tool, as well as Git Magic.
As pointed out by others, you either already created a branch and are committing on it and just mistakenly identified it as a tag here, or you actually created a tag and have been committing new commits outside of a branch and that's pretty confusing. You definitely want to read up on git branch to get a feel for how to use that if you don't already know.
It sounds like you and your team could use a work flow that supports multiple streams of release, maintenance, and development and for that I would humbly suggest this most excellent guide from Vincent Driessen. I introduced this with my team at my last employer and it changed the way we worked. Reading that should give you an incredibly good understanding of how git can best support the way it sounds like your team may already be trying to work.
There is no way to commit to an old tag directly. As pointed out by others, a tag is nothing but a name for a specific commit. However, I have a few thoughts here that may be of service to you.
You can always check out a branch based on a tag via
git checkout -b my-new-branch name-of-tag
. This will give you brand new branch based on that tag that you can then commit into. Sharing that branch becomes as simple as pushing it out to a public touch point and letting others pull it down.If you want a moving tag, you're doing something 'insane' (at least in the minds of the writers of git tags man page. They are partly right, in that moving tags are really just branch heads and thus can simply be a branch. Tags are not meant to be part of that story. If you really desire a moving tag, though, you can accomplish that by jumping through several flaming hoops and making the leap over the dagger pit by following the instruction found in the Re-Tagging Section of the
git tag
man page.
精彩评论