git 无法删除远程源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13572191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:59:00  来源:igfitidea点击:

Cannot remove remote origin

git

提问by Trevor Burnham

I'm running git 1.8.0 on OS X, and every new git repo seems to have a remote called "origin":

我在 OS X 上运行 git 1.8.0,每个新的 git repo 似乎都有一个名为“origin”的遥控器:

$ git init
$ git remote
origin

What's odd is that I can't remove it:

奇怪的是我无法删除它:

$ git remote remove origin
error: Could not remove config section 'remote.origin'

And therefore I can't add a new remote called origin. Why is this? What can I do to change it?

因此我无法添加一个名为origin. 为什么是这样?我能做些什么来改变它?

回答by Pablo Fernandez heelhook

You should be able to remove originwith

您应该能够清除origin

git remote rm origin

Not that you need to, you can just change the originwith set-url

不是你需要,你可以改变originset-url

git remote set-url origin "https://..." 

回答by Dillon Benson

Open the .git directory and edit the config file where it says [remote "origin"]

打开 .git 目录并编辑显示 [remote "origin"] 的配置文件

回答by JGallardo

WARNING: Read carefully before attempting

警告:尝试前请仔细阅读



This error can also be caused if you copy and paste a project that has git initialized. I would only recommend this in a new project where you don't care about the previous history.

如果您复制并粘贴已初始化 git 的项目,也可能导致此错误。我只会在一个你不关心以前历史的新项目中推荐这个。

Background

背景

I ran into this error when I just copied and pasted a project. When I ran git statusI saw the diff between the new project and the one that I pasted in.

当我刚刚复制和粘贴一个项目时,我遇到了这个错误。当我运行时,git status我看到了新项目和我粘贴的项目之间的差异。

Solution

解决方案

All I did to fix it was to go to the command line and cdinto the project and run

我修复它所做的只是转到命令行并cd进入项目并运行

rm -f -r .git

Which got rid of the old .git file from the previous project. Then I ran git initfor a new .git file then everything was fine.

它摆脱了上一个项目中旧的 .git 文件。然后我跑git init了一个新的 .git 文件然后一切都很好。

Likewise for this error, if you do not need the previous git records, then this is fast easy way to do it.

同样对于这个错误,如果你不需要以前的 git 记录,那么这是一个快速简单的方法。

回答by Denis Kutlubaev

I solved my problems this way. First I opened up the configfile using vimwith the following command

我这样解决了我的问题。首先,我config使用vim和以下命令打开文件

$ vim .git/config

I modified my file to this below:

我将我的文件修改为以下内容:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = false
[branch "master"]
[remote "origin"]
        url = [email protected]:xxx.git
        fetch = +refs/heads/*:refs/remotes/origin_iOS/*

So now, when I give a command git pushit understands, because by default it pushed to originand it is set to my origin_iOSin my server.

所以现在,当我发出一个命令时,git push它会理解,因为默认情况下它会推送到originorigin_iOS在我的服务器中设置为我的。

You can check your origin config by remote -vcommand:

您可以通过以下remote -v命令检查您的原始配置:

$ git remote -v
origin  [email protected]:xxxx.git (fetch)
origin  [email protected]:xxx.git (push)

If you don't have 'origin', you will have troubles with a usual 'git push'as I did. I had to type 'git push origin_iOS master', because I had in my config 'origin_iOS'

如果你没有'origin',你会'git push'像我一样遇到平常的麻烦。我必须输入'git push origin_iOS master',因为我的配置中有'origin_iOS'