【问题标题】:Git removing upstream from local repositoryGit 从本地存储库中删除上游
【发布时间】:2013-11-17 01:30:28
【问题描述】:

我正在使用 ruby​​ on rails 应用程序,我正在尝试同步一个 fork。值得一提的是,我也在 Mac 上。我执行了以下操作:

$ git remote -v

查看我的本地存储库。我在尝试去upstream时搞砸了:

$ git remote add upstream https://github.com/foo/repo.git

什么时候应该大写 Foo:

$ git remote add upstream https://github.com/Foo/repos.git

问题是如何删除upstream,因为每次我尝试更改它都会返回创建fatal 错误?

【问题讨论】:

    标签: git repository git-fetch


    【解决方案1】:

    使用 git 版本 1.7.9.5 没有远程的“删除”命令。请改用“rm”。

    $ git remote rm upstream
    $ git remote add upstream https://github.com/Foo/repos.git
    

    或者,如上一个答案所述,set-url 有效。

    我不知道命令何时更改,但 Ubuntu 12.04 附带 1.7.9.5。

    编辑:有些人似乎遇到了没有“上游”遥控器的情况。执行cat .git/config 并查看遥控器的名称。 (如果在 Windows 上而不使用 powershell,您可以使用 type .git/config。)

    输出将显示为您的 git 存储库配置的遥控器,例如,

    [remote "origin"]
    

    将您要删除的遥控器的名称替换为:

    $ git remote rm origin
    

    如果您没有“上游”遥控器,则无法将其移除。

    【讨论】:

    • 在 Windows 上,它返回错误 usage: git remote remove <name> 但不会删除上游。
    • 当你执行git remote rm upstream时它返回那个?谢谢 - 我很少使用 Windows 进行开发。
    • 致命:没有这样的远程:'上游'
    • 'git remote rm master' 给了我“致命:没有这样的遥控器:'master'”
    【解决方案2】:

    git 远程手册页非常简单:

    使用

    Older (backwards-compatible) syntax:
    $ git remote rm upstream
    Newer syntax for newer git versions: (* see below)
    $ git remote remove upstream
    
    Then do:    
    $ git remote add upstream https://github.com/Foo/repos.git
    

    或者直接更新网址:

    $ git remote set-url upstream https://github.com/Foo/repos.git
    

    或者,如果您对此感到满意,只需直接更新 .git/config - 您可能会弄清楚需要更改的内容(留给读者作为练习)。

    ...
    [remote "upstream"]
        fetch = +refs/heads/*:refs/remotes/upstream/*
        url = https://github.com/foo/repos.git
    ...
    

    ===

    * 关于 'git remote rm' 与 'git remote remove' - 这改变了 git 1.7.10.3 / 1.7.12 2 - 见

    https://code.google.com/p/git-core/source/detail?spec=svne17dba8fe15028425acd6a4ebebf1b8e9377d3c6&r=e17dba8fe15028425acd6a4ebebf1b8e9377d3c6

    Log message
    
    remote: prefer subcommand name 'remove' to 'rm'
    
    All remote subcommands are spelled out words except 'rm'. 'rm', being a
    popular UNIX command name, may mislead users that there are also 'ls' or
    'mv'. Use 'remove' to fit with the rest of subcommands.
    
    'rm' is still supported and used in the test suite. It's just not
    widely advertised.
    

    【讨论】:

    • 这个答案似乎需要更新。在 git 1.7.9 中,git remote remove upstream 产生 'error: Unknown subcommand: remove'
    • 试试 'git remote rm upstream`
    【解决方案3】:
    $ git remote remove <name>
    

    即。

    $ git remote remove upstream
    

    这应该可以解决问题

    【讨论】:

      【解决方案4】:

      在 git 版本 2.14.3 中,

      您可以使用

      删除上游
      git branch --unset-upstream
      

      上述命令也将删除跟踪流分支,因此如果你想从你已经使用的存储库中变基

      git rebase origin master 
      

      而不是git pull --rebase

      【讨论】:

      • 这非常适合我的分支,有 2 个不同的上游
      猜你喜欢
      • 2013-01-29
      • 2011-09-21
      • 1970-01-01
      • 1970-01-01
      • 2014-07-08
      • 1970-01-01
      • 1970-01-01
      • 2020-10-31
      • 1970-01-01
      相关资源
      最近更新 更多