【问题标题】:Can't change git remote origin无法更改 git 远程原点
【发布时间】:2014-02-07 08:42:45
【问题描述】:

有人可以解释为什么 git remote origin 不能从 livepost.git 更改为 Europeanexplorer.git 吗?我尝试按照说明进行操作,但文档指出 error: Could not remove config section 'remote.origin' 表示该文件不存在,这显然不是这里的情况。

$ git remote -v
origin  https://github.com/harrisongill/livepost.git (fetch)
origin  https://github.com/harrisongill/livepost.git (push)
$ git remote rm origin
error: Could not remove config section 'remote.origin'
$ git remote set-url origin https://github.com/harrisongill/europeanexplorer.git
$ git remote -v
origin  https://github.com/harrisongill/livepost.git (fetch)
origin  https://github.com/harrisongill/livepost.git (push)
origin  https://github.com/harrisongill/europeanexplorer.git (push)
$ git remote rm origin
$ git remote -v
origin  https://github.com/harrisongill/livepost.git (fetch)
origin  https://github.com/harrisongill/livepost.git (push)

编辑:添加 git 配置

$git config --list
Harrisons-MacBook-Pro:European Explorer harrison$ git config --list
user.name=Harrison Gill
user.email=my email
remote.origin.url=https://github.com/harrisongill/livepost.git
core.repositoryformatversion=0
core.filemode=true
core.logallrefupdates=true
core.precomposeunicode=true

【问题讨论】:

  • 这很不寻常。请发布您的.git/config[remote "origin"] 部分。

标签: git


【解决方案1】:

2014 年 1 月的原始答案

正如“Cannot remove remote origin”中所评论的,错误消息error: Could not remove config section 'remote.origin' 表示您的 Git 配置文件中没有远程“来源”。

至少不在您的本地配置文件中。

我刚刚测试了在我的 global 配置文件中添加一个远程“origin”部分,我得到了你所拥有的:

C:\Users\VonC\prog\git\tests\21195717\t>git config --global --edit

C:\Users\VonC\prog\git\tests\21195717\t>git remote -v
origin  https://a.com/b (fetch)
origin  https://a.com/b (push)

C:\Users\VonC\prog\git\tests\21195717\t>git remote rm origin
error: Could not remove config section 'remote.origin'

检查您的全局配置文件:

git config --global --edit

2016 年 2 月更新

Git 2.8 会将该错误消息更新为“no such remote”。

参见Thomas Gummerer (tgummerer)commit a31eeaecommit cc8e538commit 674468bcommit bc60f8a(2016 年 2 月 16 日)。
(由 Junio C Hamano -- gitster -- 合并到 commit ae2f255,2016 年 2 月 26 日)

remote:实际检查远程是否退出

将 git 远程命令转换为 211c89 中的内置命令时(“Make git-remote a builtin"),一些检查远程是否存在的调用是 转换自:

  if (!exists $remote->{$name}) {
      [...]

到:

  remote = remote_get(argv[1]);
  if (!remote)
      [...]

新的检查不太正确,因为remote_get() 永远不会返回 如果给定了名称,则为 NULL。
如果我们尝试删除不存在的远程,这会给我们留下有点神秘的错误消息“error: Could not remove config section 'remote.test'”,或者如果我们尝试重命名,则会出现类似的错误一个遥控器。

使用remote_is_configured()函数检查远程是否 确实存在,并以更明智的错误消息 ("No such remote: $remotename") 代替,如果不存在。

【讨论】:

    【解决方案2】:

    所有命令行命令都将字符串写入.git/ 目录中的文件。
    遥控器在.git/config 文件中很方便地配置,我认为这就是Chris 所指的。

    所以,如果您执行vim .git/config,您应该会看到如下内容:

    [core]
      repositoryformatversion = 0
      filemode = true
      bare = false
      logallrefupdates = true
      ignorecase = true
      precomposeunicode = false
    [remote "origin"]
      url = git@github.com:harrisongill/livepost.git
      fetch = +refs/heads/*:refs/remotes/origin/*
    

    [remote "origin"] 部分:P 中可能还有其他一些让 git 感到困惑的东西。

    为什么搞砸了?我不知道。但是,只需手动编辑此文件即可让您直截了当 :)

    摆脱多余的东西,你应该很高兴:)

    【讨论】:

    • 是的,只需要直接在.git/config文件中删除[remote "origin"]之后的内容。谢谢@apprenticeDev
    猜你喜欢
    • 2018-07-27
    • 2017-08-07
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    • 2014-04-27
    • 2017-01-07
    • 2014-09-27
    • 2013-01-15
    相关资源
    最近更新 更多