所以两个月前,我将 SVN 中的代码库迁移到 Git 中,并包含完整的变更集历史记录。紧接着,我们标记了一个新版本并继续工作。因此,当我们继续使用新标签时,有些人继续修复 SVN 中旧标签中的错误,现在我想将所有这些更改拉到 Git 中的该标签中。
我可以克隆标签并让 Git 让我向其中提交,但我无法使用 git-push 推送任何内容。检查 git-log,提交就在那里,但 git-st 告诉我我当前不在任何分支上。
那么在互联网上,我如何提交旧的 git 标签呢?
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?
发布评论
评论(7)
如果有人在搜索“替换 git tag”或类似的内容后来到这里,我推荐以下方法:
例如:
希望这对某人有帮助。
If someone is coming here after searching for "replace git tag" or something similar, I recommend the following approach:
for example:
Hope this helps someone.
标签不可移动。一旦创建了指向特定提交的标签,以后就无法更改该标签。
听起来您打算创建一个分支。您应该创建一个新分支(
gitbranchbranchname&&gitcheckoutbranchname
)以确保您不会丢失提交。然后将该分支推送到存储库,并让您的发布/错误修复开发人员在该分支中工作以进行发布。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.你指的是分支,而不是标签。 Git 中的标签是主分支中的时间点书签。虽然您可以覆盖标签 (
git tag -f
),但不建议这样做。我只会覆盖尚未部署的标签。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.如果用户使用与用户创建旧标签相同的分支,则首先创建新的更改列表。否则签出标签,然后创建新的更改列表。然后使用以下步骤使用新的变更列表编号更新现有标签
git tag -f
git push -f --tags
Total 0 (delta 0),重用 0(增量 0)
+ ...
<旧标签名称>
-><旧标签名称>
(强制更新)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)如果我正确理解你的问题,你需要在你的提交所在的地方创建一个分支。为此,请检查您要推送的版本。在 git bash 中,输入:
这应该在您的提交位置创建一个名为
old-version
的分支。然后尝试推动。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:
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.
这里发生了很多事情。
听起来您对 git 标签。我建议阅读 手册页 和还有相关部分 rel="nofollow">Pro Git。 Pro Git 还对该工具以及Git Magic。
正如其他人所指出的,您要么已经创建了一个分支并正在对其进行提交,只是错误地将其识别为此处的标签,要么您实际上创建了一个标签并一直在分支之外提交新的提交,这非常令人困惑。你肯定想阅读 git 分支如果您还不知道,请感受一下如何使用它。
听起来您和您的团队可以使用支持多个发布、维护和开发流的工作流程,为此我谦虚地建议这个来自 Vincent Driessen 的最优秀指南。我在上一家雇主那里向我的团队介绍了这一点,它改变了我们的工作方式。阅读这篇文章应该会让您对 git 如何最好地支持您的团队可能已经在尝试工作的方式有一个令人难以置信的良好理解。
无法直接提交旧标签。正如其他人所指出的,标签只不过是特定提交的名称。不过,我有一些想法可能对您有用。
您始终可以通过 git checkout -b my-new-branch name-of-tag 根据标签签出分支。这将为您提供基于该标签的全新分支,然后您可以提交该分支。共享该分支变得非常简单,只需将其推送到公共接触点并让其他人将其拉下来即可。
如果你想要一个移动标签,你就在做一些“疯狂”的事情(至少在 git tag 的手册页。他们是部分正确的,因为移动标签实际上只是分支头,因此可以简单地成为一个分支。不过,如果您确实想要一个移动标签,那么标签并不意味着成为该故事的一部分,您可以按照
git 标签
的重新标记部分代码> 手册页。
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.