git remote prune--没有像我预期的那样显示出许多修剪过的分支 [英] git remote prune – didn't show as many pruned branches as I expected
问题描述
从手册页:
删除< name>下的所有陈旧追踪分支。
这些陈旧的分支已从远程存储库
中删除,并由< name>引用,但仍在本地可用于远程/<名称>。
所以我使用
$删除了一堆分支b$ b
git push origin:staleStuff
然后运行
git remote prune origin
但是,只修剪了一个本地分支。其中一些分支由我创建,一些由同事创建。这是否表明我没有正确地跟踪那些分支?
当您使用 git push origin:staleStuff
,它会自动删除 origin / staleStuff
,所以当你运行 git remote prune origin
,你修剪了一些被其他人删除的分支。更有可能您的同事现在需要运行
git prune
来摆脱您已移除的分支。
那么究竟是什么 git remote prune
呢?主要思想:本地分支(不跟踪分支)不被 git remote prune
命令触及,应该手动删除。
您有一个包含两个分支的远程存储库: master
和功能
。假设您正在两个分支上工作,因此您在本地存储库中具有这些引用(提供完整的引用名称以避免混淆):
refs / heads / master
(简称 master
)
$ refs / heads / feature
(简称功能
)
refs / remotes / origin / master
(简称 origin / master
)
refs / remotes / origin / feature
(短名称 origin /功能
)
现在,一个典型的场景:
- 其他开发者完成了所有关于
特性
,将它合并到master
中,并从分支中移除 特性远程仓库。
- 默认情况下,当您执行
git fetch
(或git pull
),没有引用从本地存储库中删除,因此您仍然拥有所有这4个引用。 - 您决定清理它们,并运行
git remote prune origin
。 - git检测
功能分支不再存在,所以 refs / remotes / origin / feature
是一个 stale 分支,应该删除它。 - 现在您有3个引用,包括
refs / heads / feature
,因为git remote prune
不会删除任何refs / heads / *
引用。 >通过分支<< branch_name> .merge
配置参数,可以识别与远程跟踪分支关联的本地分支。这个参数对于任何工作都不是必需的(可能除了git pull
),所以它可能会丢失。
(更新为例子&来自评论的有用信息)
From the man page:
Deletes all stale tracking branches under <name>. These stale branches have already been removed from the remote repository referenced by <name>, but are still locally available in "remotes/<name>".
So I removed a bunch of branches using
git push origin :staleStuff
and then ran
git remote prune origin
However, only one single local branch was pruned. Some of these branches were created by me, some by co-workers. Does this indicate that I wasn't tracking those branches correctly in the first place?
解决方案When you use
git push origin :staleStuff
, it automatically removesorigin/staleStuff
, so when you rangit remote prune origin
, you have pruned some branch that was removed by someone else. It's more likely that your co-workers now need to rungit prune
to get rid of branches you have removed.
So what exactly
git remote prune
does? Main idea: local branches (not tracking branches) are not touched bygit remote prune
command and should be removed manually.Now, a real-world example for better understanding:
You have a remote repository with 2 branches:
master
andfeature
. Let's assume that you are working on both branches, so as a result you have these references in your local repository (full reference names are given to avoid any confusion):refs/heads/master
(short namemaster
)refs/heads/feature
(short namefeature
)refs/remotes/origin/master
(short nameorigin/master
)refs/remotes/origin/feature
(short nameorigin/feature
)
Now, a typical scenario:
- Some other developer finishes all work on the
feature
, merges it intomaster
and removesfeature
branch from remote repository. - By default, when you do
git fetch
(orgit pull
), no references are removed from your local repository, so you still have all those 4 references. - You decide to clean them up, and run
git remote prune origin
. - git detect that
feature
branch no longer exists, sorefs/remotes/origin/feature
is a stale branch which should be removed. - Now you have 3 references, including
refs/heads/feature
, becausegit remote prune
does not remove anyrefs/heads/*
references.
It is possible to identify local branches, associated with remote tracking branches, by
branch.<branch_name>.merge
configuration parameter. This parameter is not really required for anything to work (probably exceptgit pull
), so it might be missing.(updated with example & useful info from comments)
这篇关于git remote prune--没有像我预期的那样显示出许多修剪过的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!