有没有办法让我的本地git标签与遥控器的标签保持同步?也就是说 - 不仅在创建时获得新标签(像往常一样,在fetch-ing/pull-ing时),而且还不再在遥控器上修剪标签,并在其他人git push -f的标签时删除现有标签.我知道我可以git fetch remotename遵循git remote prune remotename以实现分支的类似行为.
Dom*_*erg 42
以下对我有用:
git fetch --prune --tags
Run Code Online (Sandbox Code Playgroud)
Von*_*onC 26
...也不再在遥控器上修剪标签了
git fetch 与Git 2.17(2018年第二季度)一起得到一个方便的短手,可以摆脱本地持有的陈旧标签.
请参阅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(2018年2月9日)作者:ÆvarArnfjörðBjarmason(avar).
(由Junio C gitsterHamano合并- -在提交c1a7902,2018年3月6日)
fetch:添加
--prune-tags选项和fetch.pruneTags配置添加一个
--prune-tags选项git-fetch,以及fetch.pruneTags配置选项和-P速记(-p是--prune).
这允许做以下任何一项:Run Code Online (Sandbox Code Playgroud)git fetch -p -P git fetch --prune --prune-tags git fetch -p -P origin git fetch --prune --prune-tags origin或者干脆:
Run Code Online (Sandbox Code Playgroud)git config fetch.prune true && git config fetch.pruneTags true && git fetch而不是更冗长:
Run Code Online (Sandbox Code Playgroud)git fetch --prune origin 'refs/tags/*:refs/tags/*' '+refs/heads/*:refs/remotes/origin/*'在使用此功能之前,支持从repo中拉出的用例非常痛苦,因为repo的分支和标签都被定期删除,并且我们的本地引用反映了上游.
在工作中,我们在每个卷展栏的回购中创建部署标签,并且有很多这些标签,因此出于性能原因,它们会在几周内归档.
如果没有这种改变,很难集中配置这样的存储库
/etc/gitconfig(在仅用于处理它们的服务器上).您需要fetch.prune=true全局设置,然后为每个repo设置:Run Code Online (Sandbox Code Playgroud)git -C {} config --replace-all remote.origin.fetch "refs/tags/*:refs/tags/*" "^\+*refs/tags/\*:refs/tags/\*$"现在我也可以简单地设置
fetch.pruneTags=true,/etc/gitconfig运行"git pull"的用户将自动获得我想要的修剪语义.
mlb*_*mlb 17
一些研究表明,git无法区分本地或外来标签(所有标签都转到.git/refs/tags /).因此,无法确定本地创建的标记和可修剪的远程标记之间的差异.然后将选项简化为:拥有不断增长的标记集,或仅包含服务器上的标记.
git push --tags origin && \
git tag | xargs -n1 git tag -d && \
git fetch --tags
Run Code Online (Sandbox Code Playgroud)
删除后一行为的第一行,并且可能是频繁使用的git别名.
另一种方法是在标记点创建一个分支(因为它们可以被标识为本地/远程),并且永远不会再写入它.然后使用remotename/branchname作为签出的标签将使标签保持同步(除了git fetch和之外git remote prune remotename).
无论哪种方式都是黑客攻击,"正确"的答案是不断更改标签.
使用这些命令同步标签(删除所有本地然后获取所有远程)
git tag -d $(git tag) # delete all local tags
git fetch --all # fetch all remote to local
Run Code Online (Sandbox Code Playgroud)
git push --tags会将本地标签推送到服务器.默认情况下,git fetch(git pull或git pull --rebase的前半部分)将提取标记,但您可以指定-t或--tags来拉取所有这些标记.
我不确定如何修剪远程删除的标签,但是提取应该下拉任何强制更新的标签.
另一个对我有用的解决方案:
git tag -l | xargs git tag -d && git fetch -t
Run Code Online (Sandbox Code Playgroud)
免责声明这使用了 git 内部结构(有些人可能会认为文件系统是git 接口,但那是另一天的事了 :D)
# Blow away all local tags, this will remove any that are tagged locally
# but are not on the remote
rm .git/refs/tags/*
# Download all the tags from the remote
git fetch --tags
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26230 次 |
| 最近记录: |