删除远程存储库上不再存在的本地git标签 [英] Remove local git tags that are no longer on the remote repository

查看:110
本文介绍了删除远程存储库上不再存在的本地git标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在git中使用标签作为部署过程的一部分。有时,我们希望通过从远程存储库中删除这些标签来清理这些标签。



这非常简单。一个用户在一组命令中删除本地标签和远程标签。我们有一个小脚本,它将两个步骤结合在一起。



第二个(第3,第4,...)用户现在拥有不再反映在远端的本地标记。



我正在寻找类似于 git remote prune origin 的命令,它清理本地跟踪分支,分支已被删除。



或者,可以使用一个简单的列出远程标签的命令来比较通过 git tag -l返回的本地标签。

解决方案

好的问题。 :)我没有一个完整的答案......



也就是说,您可以通过 git ls-remote获取远程标签列表。要列出由 origin 引用的存储库中的标记,您可以运行:

  git ls-remote --tags origin 

返回哈希列表和友好标签名称,如:

  94bf6de8315d9a7b22385e86e1f5add9183bcb3c refs / tags / v0.1.3 
cc047da6604bdd9a0e5ecbba3375ba6f09eed09d refs / tags / v0.1.4
...
2f2e45bedf67dedb8d1dc0d02612345ee5c893f2 refs / tags / v0.5.4

你当然可以放在一起一个bash脚本,用于比较由此列表生成的标签和本地标签。看看 git show-ref --tags ,它会以与 git ls-remote )。




另外, git show-ref 有一个选项,它与你想要的相反。以下命令将列出远程分支上 在本地的所有标记:

  git ls-remote --tags origin | git show-ref --tags --exclude-existing 


We use tags in git as part of our deployment process. From time to time, we want to clean up these tags by removing them from our remote repository.

This is pretty straightforward. One user deletes the local tag and the remote tag in one set of commands. We have a little shell script that combines both steps.

The 2nd (3rd, 4th,...) user now has local tags that are no longer reflected on the remote.

I am looking for a command similar to git remote prune origin which cleans up locally tracking branches for which the remote branch has been deleted.

Alternatively, a simple command to list remote tags could be used to compare to the local tags returned via git tag -l.

解决方案

Good question. :) I don't have a complete answer...

That said, you can get a list of remote tags via git ls-remote. To list the tags in the repository referenced by origin, you'd run:

git ls-remote --tags origin

That returns a list of hashes and friendly tag names, like:

94bf6de8315d9a7b22385e86e1f5add9183bcb3c        refs/tags/v0.1.3
cc047da6604bdd9a0e5ecbba3375ba6f09eed09d        refs/tags/v0.1.4
...
2f2e45bedf67dedb8d1dc0d02612345ee5c893f2        refs/tags/v0.5.4

You could certainly put together a bash script to compare the tags generated by this list with the tags you have locally. Take a look at git show-ref --tags, which generates the tag names in the same form as git ls-remote).


As an aside, git show-ref has an option that does the opposite of what you'd like. The following command would list all the tags on the remote branch that you don't have locally:

git ls-remote --tags origin | git show-ref --tags --exclude-existing

这篇关于删除远程存储库上不再存在的本地git标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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