检测所有本地和远程之间不同步的标签 [英] Detecting all tags that are out of sync between local and remote

查看:53
本文介绍了检测所有本地和远程之间不同步的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法来确定我在本地存储库中与远程服务器不同步的标签?不同步是指完全相同的标签名称指向不同的标签在我的本地与远程上提交.我可以想到的两种方法可能是这种情况:

Is there an easy way to determine which tags I have in my local repo that are out of sync with the remote? By out of sync I mean that the exact same tag name points to a different commit on my local vs the remote. Two ways I can think of to end up in this situation might be:

  1. 有人(或其他人)移动了我之前获取的标签.也许它已被删除并重新创建,或者在它已经存在时被强制创建.(我意识到这是不满意的,但这并不能阻止它的发生.)
  2. 我在本地创建了一个标签,然后有人(或某物)在不同的提交上创建了相同的标签名称,然后在执行之前将其推出.

表达此问题的另一种方式可能是:

Another way to word this question might be:

如果我要运行以下命令,将会更新我的哪些本地标签:

git fetch origin --tags --force

更新:基于 answer ,这支衬板应可在Git Bash中使用:

Update: based on the answer, this one liner should work in Git Bash:

diff <(git for-each-ref refs/tags --format="%(objectname)%09%(refname)") <(git ls-remote --tags | grep -v "\^{}")

说明::该命令列出了所有本地标记,并对其进行了格式设置,使其使用与 ls-remote 相同的格式.(%09是制表符.)然后区分两个输出.

Explanation: The command lists all your local tags, and formats it so that it uses the same format as ls-remote. (%09 is a tab character.) Then diff the two outputs.

推荐答案

简单"在旁观者的眼中:使用 git ls-remote --tags 转储远程标签,并使用 git for-each-ref refs/tags 检查您的本地标签.比较标记的哈希ID(在 ls-remote 输出中,这是没有后缀 ^ {} 的数字;如果有后缀,则为数字)标签的最终目标的哈希ID是一个).当名称匹配但哈希ID不同时,它们将不同步.为此,编写一个shell脚本会相对简单.

"Easy" is in the eye of the beholder: Use git ls-remote --tags to dump out the tags in the remote, and git for-each-ref refs/tags to inspect your local tags. Compare the hash IDs of the tags (in the ls-remote output, this is the number that does not have the ^{} suffix; the one with the suffix, if there is one, is the hash ID of the tag's ultimate target). When the names match but the hash IDs differ, they're out of sync. It would be relatively simple to write a shell script for this.

这篇关于检测所有本地和远程之间不同步的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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