在git中,如何将我的标签与远程服务器同步? [英] In git, how do I sync my tags against a remote server?

查看:92
本文介绍了在git中,如何将我的标签与远程服务器同步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让我的本地git标签与远程标签保持同步?这就是 - 不仅在创建时获得新的标签(通常,当 fetch -ing / pull -ing时) ,而且还可以在远程不再修剪标签,还可以在别人 git push -f 'sa标签时删除现有标签。
我知道我可以 git fetch remotename ,然后加上 git remote prune remotename 来实现分支的类似行为。

解决方案


...还可以在远程不再修剪标签

git fetch 使用Git 2.17(Q2 2018)获得
摆脱本地持有的陈旧标签。


请参阅 commit 6317972 commit e249ce0 提交627a129 commit d0e0747 commit 2c72ed7 commit e1790f9 commit 59caf52 commit 82f34e0 ,< a href =https://github.com/git/git/commit/ca3065e7e7bcb406043f8202ef672f884eeb925d =nofollow noreferrer> commit ca3065e 提交bf16ab7 提交eca142d commit 750d0da commit 0711883 commit ce3ab21 ,< a commit aa59e0e (2018年2月9日)ÆvarArnfjörðBjarmason( avar

(由 Junio C Hamano - gitster - in
$ b


抓取 :添加 - prune-tags 选项和 fetch.pruneTags config



git-fetch 添加一个 - prune-tags 选项,以及 fetch.pruneTags config选项和一个 -P 简写( -p - prune )。

这允许执行以下任何操作:

  git fetch -p -P 
git fetch --prune --prune-tags
git fetch -p -P origin $ b $ git fetch --prune - -prune-tags来源

或简单:

  git config fetch.prune true&& 
git config fetch.pruneTags true&&
git fetch

取而代之的是更详细的:

  git fetch --prune origin'refs / tags / *:refs / tags / *''+ refs / heads / *:refs / remotes / origin / * '

在此功能之前,很难支持从一个repo中拉出
,它的分支标签定期删除
,并且让我们的本地引用反映上游。

在工作中,我们在回购协议中为每个部署创建了部署标签,而
中包含很多的部分标签,因此它们会在几周内归档,出于
的性能原因。 / p>

没有此更改很难在
/ etc / gitconfig (在仅用于处理
的服务器上)。您需要全局设置 fetch.prune = true ,然后为每个
回购:

  git -C {} config --replace-all remote.origin.fetchrefs / tags / *:refs / tags / *^ \ + * refs / tags / \ * :refs / tags / \ * $

现在我可以简单地设置 / etc / gitconfig 中的$ c> fetch.pruneTags = true
以及运行 git pull 会自动获得我想要的修剪
语义。



Is there a way to keep my local git tags in lockstep with a remote's tags? That is -- not only get new tags when created (as usual, when fetch-ing/pull-ing), but also prune tags no longer on a remote and also delete existing tags when someone else git push -f's a tag. I know I can git fetch remotename followed by git remote prune remotename to achieve similar behaviour for branches.

...also prune tags no longer on a remote

git fetch gets with Git 2.17 (Q2 2018) an handy short-hand for getting rid of stale tags that are locally held.

See commit 6317972, commit 97716d2, commit e249ce0, commit 627a129, commit d0e0747, commit 2c72ed7, commit e1790f9, commit 59caf52, commit 82f34e0, commit 6fb23f5, commit ca3065e, commit bf16ab7, commit eca142d, commit 750d0da, commit 0711883, commit ce3ab21, commit aa59e0e (09 Feb 2018) by Ævar Arnfjörð Bjarmason (avar).
(Merged by Junio C Hamano -- gitster -- in commit c1a7902, 06 Mar 2018)

fetch: add a --prune-tags option and fetch.pruneTags config

Add a --prune-tags option to git-fetch, along with fetch.pruneTags config option and a -P shorthand (-p is --prune).
This allows for doing any of:

git fetch -p -P
git fetch --prune --prune-tags
git fetch -p -P origin
git fetch --prune --prune-tags origin

Or simply:

git config fetch.prune true &&
git config fetch.pruneTags true &&
git fetch

Instead of the much more verbose:

git fetch --prune origin 'refs/tags/*:refs/tags/*' '+refs/heads/*:refs/remotes/origin/*'

Before this feature it was painful to support the use-case of pulling from a repo which is having both its branches and tags deleted regularly, and have our local references to reflect upstream.

At work we create deployment tags in the repo for each rollout, and there's lots of those, so they're archived within weeks for performance reasons.

Without this change it's hard to centrally configure such repos in /etc/gitconfig (on servers that are only used for working with them). You need to set fetch.prune=true globally, and then for each repo:

git -C {} config --replace-all remote.origin.fetch "refs/tags/*:refs/tags/*" "^\+*refs/tags/\*:refs/tags/\*$"

Now I can simply set fetch.pruneTags=true in /etc/gitconfig as well, and users running "git pull" will automatically get the pruning semantics I want.

这篇关于在git中,如何将我的标签与远程服务器同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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