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

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

问题描述

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



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



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



我知道我可以强制在新提交上创建相同的标签,但我相信应该是一种更好的方式(就像使用修改提交的命令行参数)。 解决方案

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



为了获得git工作的良好背景,请看一看在Scott Chacon的Rails Conference上谈论gitcasts.com上的git。另外,请阅读git:progit.org/book上的简短书。


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 ?

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").

解决方案

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.

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天全站免登陆