如何在 Git 中标记较旧的提交? [英] How to tag an older commit in Git?

查看:21
本文介绍了如何在 Git 中标记较旧的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We are new to git, and I want to set a tag at the beginning of our repository. Our production code is the same as the beginning repository, but we've made commits since then. A tag at the beginning would allow us to "roll back" production to a known, stable state.

那么如何向任意的、较旧的提交添加标签?

So how to add a tag to an arbitrary, older commit?

推荐答案

示例:

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

其中 9fceb02 是提交 ID 的开始部分.

Where 9fceb02 is the beginning part of the commit id.

然后您可以使用 git push origin v1.2 推送标签.

You can then push the tag using git push origin v1.2.

您可以执行 git log 来显示当前分支中的所有提交 ID.

You can do git log to show all the commit id's in your current branch.

Pro Git 中还有一个关于标记的好章节书.

There is also a good chapter on tagging in the Pro Git book.

警告:这会创建带有当前日期的标签(例如,该值将显示在 GitHub 发布页面上).如果您希望标签与提交日期一起注明日期,请查看另一个答案.

Warning: This creates tags with the current date (and that value is what will show on a GitHub releases page, for example). If you want the tag to be dated with the commit date, please look at another answer.

这篇关于如何在 Git 中标记较旧的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆