本文介绍了git fetch origin --prune不会删除本地分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一次,我认为 git fetch origin --prune 删除了服务器上不存在的本地分支。不知何故,这不是我目前的经验。

At one point I thought that git fetch origin --prune deleted local branches that were no longer present on the server. Somehow this is not my experience at the moment.

我运行了这个命令,本地分支没有被删除。目前没有 签出。我运行了 git branch -vv 来检查这个信息,我看到

I ran this command, and the local branch was not deleted. It is not currently checked out. I ran git branch -vv to check this info, and I see

feature/MyGreatFeature           f30efc7 [origin/feature/MyGreatFeature: gone]

所以它似乎知道它离开了。为什么它不会删除我的本地分支?

So it seems to know that it is gone. Why would it not delete my local branch?

运行 git version 2.7.4(Apple Git-66)

推荐答案

各种修剪选项( git remote update --prune code> git remote prune , git fetch --prune only 删除远程追踪分支。 sup> 1

The various prune options (git remote update --prune, git remote prune, git fetch --prune) only delete remote-tracking branches.

您需要手动删除不再需要的本地分支,或者如果远程跟踪分支为no,则需要更改或移除其上游设置更长的存在。请注意,每个本地分支可以记录现在不存在甚至从未存在的远程和/或分支。在这种情况下,Git的主要作用就好像这些本地分支没有上游设置,除了从版本1.8.5开始,几个命令报告上游为消失或其他无效,并且可以建议使用 - unset -upstream

You'll need to manually delete local branches you no longer want, or change or remove their upstream setting if the remote-tracking branch no longer exists. Note that each local branch can record a remote and/or branch that do not now, or even never did, exist. In this case Git mostly acts as if those local branches have no upstream set, except that since version 1.8.5, several commands report the upstream as "gone" or otherwise invalid, and may suggest using --unset-upstream.

更准确地说,在从命令行执行refspec映射后执行,或者从配置执行 fetch 行。因此,对于提取镜像,它们可以删除本地分支。不过,大多数克隆并没有设置为获取镜像。

More precisely, they delete destination refs after doing the refspec mapping from the command line or fetch lines from the configuration. Hence, for fetch mirrors, they can delete local branches. Most clones are not set up as fetch mirrors, though.

对于复杂映射,最近有一些错误修复,以确保Git在某些情况下不修剪映射分支当它不应该的情况下。对于任何正常的存储库 - 普通克隆或纯获取镜像 - 这些修补程序不起作用;它们只在复杂 fetch 配置时才有意义。

There were some recent bug fixes for complex mappings, to make sure that Git did not prune a mapped branch in some cases when it should not. For any normal repository—ordinary clone or pure fetch mirror—these fixes have no effect; they matter only if you have complicated fetch configurations.

这篇关于git fetch origin --prune不会删除本地分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:58