git 远程修剪 –没有显示出我预期的那么多修剪过的树枝
从手册页:
删除
下的所有过时跟踪分支。 这些过时的分支已从远程存储库中删除 由 引用,但仍可在“remotes/ ”中本地使用。
所以我使用删除了一堆分支
git push origin :staleStuff
,然后运行
git remote prune origin
但是,只修剪了一个本地分支。其中一些分支是我创建的,一些是同事创建的。这是否表明我一开始就没有正确跟踪这些分支?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用 git push origin :staleStuff 时,它会自动删除 origin/staleStuff ,因此当您运行 git remote prune origin 时,您已经修剪了一些被别人删除的分支。您的同事现在更有可能需要运行 git prune 来删除您已删除的分支。
那么 git Remote prune 到底是做什么的呢?主要思想:本地分支(不是跟踪分支)不会被 git remote prune 命令触及,应该手动删除。
现在,通过一个现实世界的示例来更好地理解:
您有一个包含 2 个分支的远程存储库:
master
和feature
。假设您正在两个分支上工作,因此您的本地存储库中有这些引用(给出了完整的引用名称以避免任何混淆):refs/heads/master
(简称<代码>master)refs/heads/feature
(简称feature
)refs/remotes/origin/master
(简称< code>origin/master)refs/remotes/origin/feature
(简称origin/feature
)现在,一个典型的场景:
feature
上,将其合并到master
并从远程存储库中删除feature
分支。feature
分支不再存在,因此refs/remotes/origin/feature
是一个陈旧分支,应该将其删除。可以通过
branch..merge
配置参数来识别与远程跟踪分支关联的本地分支。这个参数对于任何东西的工作来说并不是真正需要的(可能除了 git pull ),所以它可能会丢失。(使用评论中的示例和有用信息进行更新)
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:
feature
, merges it intomaster
and removesfeature
branch from remote repository.git fetch
(orgit pull
), no references are removed from your local repository, so you still have all those 4 references.git remote prune origin
.feature
branch no longer exists, sorefs/remotes/origin/feature
is a stale branch which should be removed.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)