git remote prune--没有像我预期的那样显示出许多修剪过的分支 [英] git remote prune – didn't show as many pruned branches as I expected

查看:431
本文介绍了git remote prune--没有像我预期的那样显示出许多修剪过的分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从手册页:


 删除< 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 /功能


现在,一个典型的场景:


  1. 其他开发者完成了所有关于特性,将它合并到 master 中,并从分支中移除特性远程仓库。

  2. 默认情况下,当您执行 git fetch (或 git pull ),没有引用从本地存储库中删除,因此您仍然拥有所有这4个引用。

  3. 您决定清理它们,并运行 git remote prune origin

  4. git检测功能分支不再存在,所以 refs / remotes / origin / feature 是一个 stale 分支,应该删除它。

  5. 现在您有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 removes origin/staleStuff, so when you ran git 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 run git 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 by git 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 and feature. 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 name master)
    • refs/heads/feature (short name feature)
    • refs/remotes/origin/master (short name origin/master)
    • refs/remotes/origin/feature (short name origin/feature)

    Now, a typical scenario:

    1. Some other developer finishes all work on the feature, merges it into master and removes feature branch from remote repository.
    2. By default, when you do git fetch (or git pull), no references are removed from your local repository, so you still have all those 4 references.
    3. You decide to clean them up, and run git remote prune origin.
    4. git detect that feature branch no longer exists, so refs/remotes/origin/feature is a stale branch which should be removed.
    5. Now you have 3 references, including refs/heads/feature, because git remote prune does not remove any refs/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 except git pull), so it might be missing.

    (updated with example & useful info from comments)

    这篇关于git remote prune--没有像我预期的那样显示出许多修剪过的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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