git:有类似每个分支标签的东西吗?
我有一些历史重写要做,为此我想暂时保持我原来的树完好无损。然而,重写的树也应该复制以前使用的标签。是否有比在分支名称前面添加标签名称更少的手动选项?
I have some history rewriting to do for which I'd like to keep my original tree intact for now. The rewritten tree should however copy the tags previously used as well. Is there any less manual option than e.g. prepending tag names with the branch name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,git 中没有像每个分支标签那样的东西。所有分支和标签都只是 Git 中的引用; ref 只是指向修订历史记录中特定修订的名称。例如,如果您有
devel
和master
分支以及v1.0
和v2.0
标记,则引用看起来像这样:正如您所看到的,没有任何东西将这些标签绑定到任何分支;事实上,所有这些标签都包含在
master
和devel
分支中。通过查看您的.git
存储库,您可以发现标签实际上没有比这更多的结构了;它只是一个包含 SHA-1 的文件,引用.git/refs
中的提交,或者.git/packed-refs
中的一行(标签通常位于 < code>packed-refs 因为它们不经常更改,而分支通常是git/refs
中的单独文件。因此,如果您想重写历史记录并保留旧标签,则必须重写标签名称。正如 sehe 指出的,这是使用
git filter-branch --tag-name-filter
。No, there is nothing like a per-branch tag in git. All branches and tags are just kinds of refs in Git; a ref is just a name that points to a particular revision in the revision history. For instance, if you have
devel
andmaster
branches, andv1.0
andv2.0
tags, the references would look something like this:As you can see, there's nothing tying those tags to any branches; in fact, all of those tags are contained in both the
master
anddevel
branches. By looking inside your.git
repo, you can see that there is really no more structure to a tag than that; it is just a file containing a SHA-1 referencing a commit within.git/refs
, or a line in.git/packed-refs
(tags will frequently be inpacked-refs
because they don't change often, while branches will usually be separate files withingit/refs
).So if you want to rewrite history, and preserve the old tags, you will have to rewrite your tag names. As sehe points out, this is done using
git filter-branch --tag-name-filter
.您可以将标签命名为以您希望标签(某种)所属的分支命名的目录,并且不必是手动的:
You can namespace a tag into a directory named after the branch you want the tag to (kind of) belong to, and it doesn't have to be manual: