当您修改已标记的提交时,Git 中的标记会发生什么? [英] What happens in Git to a tag when you amend the commit that was tagged?

查看:24
本文介绍了当您修改已标记的提交时,Git 中的标记会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将一些源文件提交到我的 git 存储库并将其标记为我的软件的新版本.但是我看到了我刚刚犯的一个错误,并使用了修改"功能来提交更正的文件.

I have committed a few source files to my git repository and tagged it as a new version of my software. But I saw a mistake I had just made and used the "amend" feature to commit the corrected files.

现在,我看到标签没有转移到新的提交(使用修改"功能制作的那个).但我也可以看到标签仍然存在......

Now, I see that the tag was not transferred to the new commit (the one made with the "amend" feature). But I can also see that the tag still exists...

我想知道标签发生了什么.这种行为是错误吗?标签是否链接到不再存在的提交?

I would like to know what happened to the tag. Is this behavior a bug? Is the tag linked to a commit which doesn't exist anymore ?

我知道我可以在新的提交上强制创建相同的标签,但我相信应该有更好的方法(比如在提交上使用amend"的命令行参数).

I know I can force the creation of the same tag on the new commit, but I believe there should be a better way (like a command line parameter on the commit using "amend").

推荐答案

这是设计使然.Git 将提交、标签、blob 和树作为其内容的 SHA-1 哈希值进行跟踪.它们只是指向对象的指针.标签指向的对象仍然存在.这是您修改之前的提交版本.只需删除标签并重新创建它.如果他们从该提交开始任何事情,请确保让使用存储库的其他人知道您做了什么.

This is by design. Git tracks commits, tags, blobs and trees as SHA-1 hashes of their contents. They are simply pointers to the objects. The object that the tag points to is still there. This is the version of the commit before you amended it. Just delete the tag and create it again. Ensure that you let others that are using the repository know what you did if they started anything from that commit.

要了解 git 的工作原理,请查看 Scott Chacon 在 gitcasts.com 上关于 git 的 Rails 会议讨论.另外,请阅读关于 git 的短书:progit.org/book.

To get a good background of how git works, take a look at Scott Chacon's Rails Conference talk about git on gitcasts.com. Also, read the short book on git: progit.org/book.

这篇关于当您修改已标记的提交时,Git 中的标记会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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