如何提交旧的 git 标签?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4150944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:26:52  来源:igfitidea点击:

How can I commit to an old git tag?

gitgithubgit-svn

提问by Jon Ursenbach

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.

所以两个月前,我将我们在 SVN 中的代码库迁移到 Git 中,并带有完整的变更集历史记录。紧接着,我们标记了一个新版本并继续工作。因此,虽然我们继续在新标签上工作,但有些人继续在 SVN 中修复旧标签中的错误,现在我想将所有这些更改拉入 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.

我可以克隆标签并使 Git 允许我向其中提交,但我无法使用 git-push 将任何内容推回原处。检查 git-log,提交就在那里,但 git-st 告诉我我目前不在任何分支上。

So Internet, how can I commit to an old git tag?

那么互联网,我怎样才能承诺一个旧的 git 标签?

采纳答案by cdhowie

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 branch branchname && git checkout branchname) 以确保您不会丢失您的提交。然后将该分支推送到存储库,并让您的发布/错误修复开发人员在该分支中工作以进行发布。

回答by toobulkeh

If someone is coming here after searching for "replace git tag" or something similar, I recommend the following approach:

如果有人在搜索“replace git tag”或类似内容后来到这里,我推荐以下方法:

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.

希望这可以帮助某人。

回答by Vic

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 中的标签是 master 分支中的时间点书签。虽然您可以覆盖标签 ( git tag -f),但不建议这样做。我只会覆盖尚未部署的标签。

回答by Kaustuv Maji

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 tag -f <old tag name>

git push -f --tags

git push -f --tags

Total 0 (delta 0), reused 0 (delta 0) + ... <old tag name>-> <old tag name>(forced update)

总计 0 (delta 0), 重用 0 (delta 0) + ... <old tag name>-> <old tag name>(强制更新)

回答by Tim Visher

There's a number of things going on here.

这里发生了很多事情。

  1. It sounds like you don't have an adequate understanding of the purpose of git tag. I'd recommend reading that man pageand also the relevant sectionof Pro Git. Pro Gitalso makes an excellent introduction in general to the tool, as well as Git Magic.

  2. 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 branchto get a feel for how to use that if you don't already know.

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

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

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

    2. 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 Sectionof the git tagman page.

  1. 听起来您对git tag的目的没有足够的了解。我建议你阅读该手册页,也是相关部门专业的GitPro Git还对该工具以及Git Magic进行了出色的总体介绍。

  2. 正如其他人指出的那样,您要么已经创建了一个分支并正在对其进行提交,只是在这里错误地将其标识为标签,要么您实际上创建了一个标签并一直在分支外提交新的提交,这非常令人困惑。如果您还不知道如何使用它,您肯定想阅读git branch以了解如何使用它。

  3. 听起来您和您的团队可以使用支持多个发布、维护和开发流的工作流程,为此,我虚心推荐Vincent Driessen 的这篇最出色的指南。我在上一家雇主处向我的团队介绍了这一点,它改变了我们的工作方式。阅读这篇文章应该会让你对 git 如何最好地支持听起来你的团队可能已经在努力工作的方式有一个非常好的理解。

  4. 无法直接提交旧标签。正如其他人所指出的,标签只不过是特定提交的名称。但是,我在这里有一些想法可能对您有用。

    1. 您始终可以通过git checkout -b my-new-branch name-of-tag. 这将为您提供基于该标签的全新分支,然后您可以将其提交。共享该分支就像将其推送到公共接触点并让其他人将其拉下来一样简单。

    2. 如果你想要一个移动标签,你正在做一些“疯狂”的事情(至少在git tag手册页的作者的脑海中。他们是部分正确的,因为移动标签实际上只是分支头,因此可以简单地一个分支。标签并不意味着成为那个故事的一部分。但是,如果你真的想要一个移动的标签,你可以通过跳过几个燃烧的箍并按照Re 中的说明跳过匕首坑来实现这一点。-Tagging节的的git tag手册页。

回答by Sven Marnach

You should create a new branch at the position of the tag, delete the tag, make your commits, recreate the tag and push.

您应该在标签位置创建一个新分支,删除标签,进行提交,重新创建标签并推送。

回答by Smashery

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 bash 中,输入:

git branch old-version

This should create a branch at the location of your commit called old-version. Then try pushing.

这应该在您的提交位置创建一个名为old-version. 然后尝试推动。