从 git 远程推送 URL 中删除错误写入的 URL

Remove incorrectly written URL from git remote push URL

我遇到过这种情况:

$ git remote show origin
* remote origin
  Fetch URL: git@gits-15.sys.kth.se:/gruprog-20/hansji-p-uppgift.git
  Push  URL: https://github.com/kulkarninomizuproduct/p-uppgift.git
  Push  URL: ^C
  Push  URL: ^C
  Push  URL: git@gits-15.sys.kth.se:/gruprog-20/hansji-p-uppgift.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (fast-forwardable)

当我试图复制一些东西时发生了这种情况,当我按下 ctrl+C 时,“^C”被意外添加为推送 URL 到我名为“origin”的遥控器(虽然我从未按下过进入)。我尝试了许多不同的命令来删除它:

$ git remote remove ^C
$ git remote rm ^C
$ git remote rm url ^C
$ git remote set-url --delete --push ^C
$ git remote set-url --delete ^C
$ git remote set-url --delete --push <^C>
$ git remote set-url --delete --push origin ^C

我怀疑 URL 实际上不是“^C”,而是实际的命令 ctrl+C 因为看看这个区别:

#When I write "git remote rm", then ctrl+C (as above, I dont need to press enter)(it returns nothing):

$ git remote rm ^C


# When I write "git remote ^C"

$ git remote rm ^C
fatal: No such remote: '^C'

您需要指定要删除的遥控器,因此 origin 在本例中,如下所示:

git remote remove origin

你也可以使用set-url来改变遥控器URL(改变URL为实际来源git/https URL):

git remote set-url origin URL

如果这两个都不适合您,您可以从项目的根目录手动编辑以下文件:

.git/config

里面应该有这样的内容:

[remote "origin"]
        url = ...
        fetch = +refs/heads/*:refs/remotes/origin/*