向现有 Git 标签添加新提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21459540/
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 17:39:01  来源:igfitidea点击:

Add new commit to the existing Git tag

gitgithubgit-branchgit-svngit-tag

提问by PVH

I have created a Git tag as v1.1using

我创建了一个 Git 标签作为v1.1使用

git tag -a v1.1 -m 'my version 1.1'

and I pushed that tag. Later, I made some changes related to v1.1. Now when I push new changes and check the git tag using git describeit is showing me v1.1-g2dcc97.

我推了那个标签。后来,我做了一些与v1.1. 现在,当我推送新的更改并使用git describe它检查 git 标签时, 它向我显示v1.1-g2dcc97.

How can I add my new commit to the existing tag?

如何将我的新提交添加到现有标签?

回答by Chris

You can't put a new commit into an existing tag without breaking an important Git guideline: Never(*) modify commits that you have published.

你不能在不违反一个重要的 Git 准则的情况下将新提交放入现有标签:从不(*) 修改你已发布的提交。

Tags in Git aren't meant to be mutable. Once you push a tag out there, leave it alone.

Git 中的标签并不意味着是可变的。一旦你把标签推出去,别管它。

You can, however, add some changes on top of v1.1and release something like v1.1.1or v1.2. One way of doing that would be

但是,您可以在其上添加一些更改v1.1并发布诸如v1.1.1或 之类的内容v1.2。这样做的一种方法是

# Create a new branch from tag v1.1
git checkout -b newbranch v1.1

# Do some work and commit it

# Create a new tag from your work
git tag -a -m "Tag version 1.1.1, a bugfix release" v1.1.1

(*) Unless you have a really super special reason for doing so, and only if you completely understand the implications, and even then, don't make a habit of it.

(*) 除非你有一个非常特别的理由这样做,而且只有当你完全理解其中的含义,即使那样,也不要养成习惯。

回答by papigee

If you absolutelyneed to "move" the tag instead of creating a new one, You can do this:

如果您绝对需要“移动”标签而不是创建一个新标签,您可以这样做:

NB: As @Chrissaid, make sure you have a good reason for not wanting to create a new tag because the best practice is to create a new one

注意:正如@Chris所说,确保您有充分的理由不想创建新标签,因为最佳做法是创建一个新标签

1.Checkout the tag (a Detached HEAD)

1.签出标签(一个分离的 HEAD)

git checkout tag/v1.1

git checkout tag/v1.1

2.Create and Checkout a branch off that tag (i.e. Branching off the tag)

2.创建和检出该标签的分支(即从标签分支)

git checkout -b my-tagged-branch

git checkout -b my-tagged-branch

*** do work and commit changes ***

*** do work and commit changes ***

3.Push to the remote branch.

3.推送到远程分支。

git push  -u origin my-tagged-branch

If needed merge branch into other branches that need the change (in case of a bug fix for example)

如果需要,将分支合并到需要更改的其他分支中(例如,在错误修复的情况下)

4.While still on my-tagged-branch, Delete the tag

4.仍然亮着my-tagged-branch,删除标签

git tag -d v1.1

git tag -d v1.1

5.Create the tag again: This will "move" the tag to point to your latest commit on that branch

5.再次创建标签:这将“移动”标签以指向您在该分支上的最新提交

git tag v1.1

git tag v1.1

6.Delete the tag on remote

6.删除遥控器上的标签

git push origin :v1.1

git push origin :v1.1

7.Create the tag on remote

7.在远程创建标签

git push origin v1.1

git push origin v1.1