关于版本控制:如何在Git中标记旧的提交?

How to tag an older commit in Git?

我们是Git的新手,我想在存储库的开头设置一个标记。我们的生产代码与初始存储库相同,但从那时起我们就进行了提交。一开始的标签将允许我们将生产"回滚"到一个已知的、稳定的状态。

那么,如何将标记添加到一个任意的、较旧的提交中呢?


实例: </P >

1
git tag -a v1.2 9fceb02 -m"Message here"

9fceb02是开始部分的承诺的ID。 </P >

然后,你可以使用git push origin v1.2推的标签。 </P >

你能做的git log秀的所有承诺的ID的流在你的店。 </P >

也有一个好的第tagging Pro是在‘出去的书。 </P >

警告:本创源标签与当前日期(是什么值,将显示A GitHub发布页,for example)。如果你想在标签是日期与承诺的日期,请看在另一个的答案。 </P >


是代码

1
2
3
4
5
6
7
8
9
# Set the HEAD to the old commit that we want to tag
git checkout 9fceb02

# temporarily set the date to the date of the HEAD commit, and add the tag
GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" \
git tag -a v1.2 -m"v1.2"

# set HEAD back to whatever you want it to be
git checkout master

详细资料

在回答"dkinzer创源标签用谁的日期是当前日期(当你在命令行git tag类风湿关节炎(RA),而不是日期的承诺。"‘出去帮助中心有一个tag型"的追溯标签"这是说: </P >

If you have imported some changes from another VCS and would like to add tags for major releases of your work, it is useful to be able to specify the date to embed inside of the tag object; such data in the tag object affects, for example, the ordering of tags in the gitweb interface.

To set the date used in future tag objects, set the environment variable GIT_COMMITTER_DATE (see the later discussion of possible values; the most common form is"YYYY-MM-DD HH:MM").

For example:

1
$ GIT_COMMITTER_DATE="2006-10-02 10:31" git tag -s v1.0.1

页,"如何标记在NEA的交往"的美国,我们可以提取的时间的承诺:通过头 </P >

1
2
git show --format=%aD  | head -1
#=> Wed, 12 Feb 2014 12:36:47 -0700

我们可能会提取日期的一个承诺:通过特异性 </P >

1
2
GIT_COMMITTER_DATE="$(git show 9fceb02 --format=%aD | head -1)" \
git tag -a v1.2 9fceb02 -m"v1.2"

但是,在去大学的repeating两次的承诺,它看来,easier OP是改变的那一头的承诺和使用它在两implicitly commands: </P >

1
2
3
git checkout 9fceb02

GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" git tag -a v1.2 -m"v1.2"


在扩通这样做是 </P >

git tag v1.0.0 f4ba1fc </P >

f4ba1fc被在开始的哈希的承诺你想要的标签和v1.0.0版中有你想要的标签。 </P >


使用命令行: </P >

1
git tag v1.0 ec32d32

在惨案完美汉化破解免费下载是标签的名称和ec32d32承诺是你想要的标签 </P >

你可以一次做推的方式进行: </P >

1
git push origin --tags

参考: </P >

‘出去(修订控制):如何我能特异性标记A点之前的承诺在GitHub上??????? </P >


好的,你可以做的是: </P >

1
git tag -a <tag> <commit-hash>

所以如果你想添加标签:1.0.2 TO COMMIT e50f795,只是简单的做: </P >

1
git tag -a 1.0.2 e50f795

也你添加的消息在端,采用-m,这样的东西: </P >

1
git tag -a 1.0.2 e50f795 -m"my message"

在所有的,你需要推到它的remote,做这,做简单的: </P >

1
git push origin 1.0.2

如果你有很多的标签'你不想和他们一个一个值得一提的是,简单的做: </P >

1
git push origin --tags

全推到一起的方式………………… </P >

也,我创建的步骤在下面的图像,为更多的clarification的步骤: creating tag on a commit hash </P >

你可以冲DD的标签在集线器或用工具式的sourcetree,避免在以前的步骤,我logged在给我的bitbucket在这个案例和做它从那里。 </P >

  • 去你的店找到的承诺和你想添加的标签和点击到它:
  • find your commit in bitbucket </P >

  • 在COMMIT的页面,在右键,找到它在说No tags和点击的+图标:
  • find where it says No tags </P >

  • 在tag name框,添加你的标签:
  • add tag name </P >

  • 现在你看到的是"successfully创建标签有:
  • enter image description here </P >


    这是一个老问题和解答,已给定的所有的工作,但有一个新的选项,这也可以考虑。 </P >

    如果你是用你的sourcetree到美国NEA库,你可以右键单击任何承诺和一个标签添加到它。与另一个你可以点击鼠标也派的标签,直到分支的起源。 </P >


    建筑河畔的回答的人,这里是A的一套解决方案,集的标签的日期到当它真的发生时,使用的annotated标签和requires git checkout:好的 </P >

    1
    2
    tag="v0.1.3" commit="8f33a878" bash -c 'GIT_COMMITTER_DATE="$(git show --format=%aD $commit)" git tag -a $tag -m $tag $commit'
    git push --tags origin master

    tag是集的desired标签的字符串,和commit哈希的承诺。 </P >


    "答案"的phrogz是伟大的,但不工作的Windows。这里的如何在标签的承诺与承诺的原日期,使用PowerShell的: </P >

    1
    2
    3
    4
    git checkout 9fceb02
    $env:GIT_COMMITTER_DATE = git show --format=%aD | Select -First 1
    git tag v1.2
    git checkout master