问题描述
我已经使用
git tag -a v1.1 -m 'my version 1.1'
,然后我推了那个标签.后来,我做了一些与v1.1
相关的更改.现在,当我推送新更改并使用来检查git标签时git describe
它向我显示v1.1-g2dcc97
.
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 usinggit describe
it is showing me v1.1-g2dcc97
.
如何将新提交添加到现有标签?
How can I add my new commit to the existing tag?
推荐答案
在不破坏重要的Git准则的情况下,您不能将新提交提交到现有标签中:从不(*)修改已发布的提交.
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.
但是,您可以在v1.1
之上添加一些更改,并发布v1.1.1
或v1.2
之类的内容.做到这一点的一种方法是
You can, however, add some changes on top of v1.1
and release something like v1.1.1
or v1.2
. One way of doing that would be
# 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.
这篇关于向现有的Git标签添加新的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!