Git:区分本地和远程标签 [英] Git: distinguish between local and remote tags
问题描述
如果远程存储库中有标签,我通常会在拉动时自动获取它们。当我删除创建的本地标记( git tag -d
)并拉出时,删除的标记将被重新创建。我可以删除远程分支/标签( git push<远程分支/标签名称>:< branch / tag-name>
),但我怎么能检测到本地标记是通过获取远程标记创建的? 解决方案
如果您对这些感到恼火标签在运行 git pull
时被重新创建,您可以使用 remote。< remote-name> .tagopt 配置设置。例如如果远程是 origin
,那么你可以这样做:
git config remote.origin.tagopt --no-tags
更新:您的评论,我建议这样做的原因是,没有一种明显的方式来区分在本地创建的标记和从远程获取的标记之间的区别。标签也没有 reflog
。所以,我的建议是禁止自动获取标签 - 然后您可以将它们自己获取到不同的名称空间中。例如,你可以这样做:
git fetch origin + refs / tags / *:refs / tags / origin / *
...也许为此创建一个别名。然后,当您要抓取标签时,它们将被命名,例如 refs / tags / origin / tag1
,而不是 refs / tags / tag1
。
如果您希望自动发生这种情况,可以将 .git / config
列出多个用于提取的refspecs,例如:
[remoteorigin ]
url = whoever @ whereever:whatever.git
fetch = + refs / heads / *:refs / remotes / origin / *
fetch = + refs / tags / *:refs / tags / origin / *
...这是在Pro Git中建议。
If there are tags in the remote repository, I'm usually getting them automatically when pulling. When I delete the created local tag (git tag -d <tag-name>
) and pull, the deleted tag will be recreated. I can delete remote branches/tags (git push <remote-branch/tag-name>:<branch/tag-name>
), but how can I detect that the local tag was created by fetching a remote tag?
If you're annoyed about these tags being recreated when you run git pull
, you turn off the fetching of tags by default with the remote.<remote-name>.tagopt config setting. e.g. if the remote is origin
, then you can do:
git config remote.origin.tagopt --no-tags
Update: to address your comment, the reason that I suggest this is that there's not an obvious way to tell the difference between a tag that was created locally and one that was fetched from a remote. There's also no reflog
for tags. So, my suggestion is to suppress automatic fetching of tags - you can then fetch them yourself into a different namespace. For example, you could do:
git fetch origin +refs/tags/*:refs/tags/origin/*
... and perhaps create an alias for that. Then when you want to fetch tags, they'll be named, for example, refs/tags/origin/tag1
instead of refs/tags/tag1
.
If you want this to happen automatically, you could change your .git/config
to list multiple refspecs for fetching, e.g.:
[remote "origin"]
url = whoever@whereever:whatever.git
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/tags/*:refs/tags/origin/*
... which is suggested in Pro Git.
这篇关于Git:区分本地和远程标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!