使用'git remote add origin'创建一个全局远程,而不是当前目录/ repo的一个本地

时间:2011-09-10 04:53:11

标签: linux git ubuntu github ubuntu-10.04

解决方案:终于实现了问题。愚蠢的用户错误。忘了先在新项目目录中运行' git init '。因此,运行' git add。',' git remote add origin repo.git '(甚至是拼写错误' git add origin repo.git ')在没有git repo的目录中,将恢复为全局应用命令,因此 git status 中的所有父目录和其他目录都会产生。


我一直在使用git并且从未遇到过这个问题,不知道发生了什么。简而言之,使用'git remote add origin git@github.com...'在整个文件系统中创建一个全局远程,而不是仅在当前目录中创建本地远程。它甚至会覆盖其他横向目录中的遥控器。

代码胜过千言万语,任何人都知道这里发生了什么:

prompt:~/bin/Projects$ ls -al
total 56
drwxr-xr-x 15 kurtosis kurtosis 4096 2011-09-09 21:35 .
drwxr-xr-x 26 kurtosis kurtosis 4096 2011-09-09 21:35 ..
drwxr-xr-x  5 kurtosis kurtosis 4096 2011-06-16 13:42 byrongibson.com
drwxr-xr-x  5 kurtosis kurtosis 4096 2011-06-16 13:44 byrongibson.github.com
drwxr-xr-x  3 kurtosis kurtosis 4096 2011-09-09 21:33 know.io
drwxr-xr-x  3 kurtosis kurtosis 4096 2011-06-16 13:45 problem-sets
drwxr-xr-x  2 kurtosis kurtosis 4096 2011-07-18 20:11 vim~
prompt:~/bin/Projects$ git remote -v
prompt:~/bin/Projects$ cd know.io/
prompt:~/bin/Projects/know.io$ ls -al
total 16
drwxr-xr-x  3 kurtosis kurtosis 4096 2011-09-09 21:33 .
drwxr-xr-x 15 kurtosis kurtosis 4096 2011-09-09 21:35 ..
-rw-r--r--  1 kurtosis kurtosis    7 2011-09-09 21:27 README.md
drwxr-xr-x  2 kurtosis kurtosis 4096 2011-09-09 21:27 vim~
prompt:~/bin/Projects/know.io$ git remote -v
prompt:~/bin/Projects/know.io$ git remote add origin git@github.com:byrongibson/know.io.git
prompt:~/bin/Projects/know.io$ git remote -v
origin  git@github.com:byrongibson/know.io.git (fetch)
origin  git@github.com:byrongibson/know.io.git (push)
prompt:~/bin/Projects/know.io$ cd ..
prompt:~/bin/Projects$ git remote -v
origin  git@github.com:byrongibson/know.io.git (fetch)
origin  git@github.com:byrongibson/know.io.git (push)
prompt:~/bin/Projects$ cd ~
prompt:~$ git remote -v
origin  git@github.com:byrongibson/know.io.git (fetch)
origin  git@github.com:byrongibson/know.io.git (push)
prompt:~$ cd bin/Github
prompt:~/bin/Github$ git remote -v
origin  git@github.com:byrongibson/know.io.git (fetch)
origin  git@github.com:byrongibson/know.io.git (push)
prompt:~/bin/Github$ 

Update1:​​这个问题神秘地消失了。不知道我做了什么或为什么。如果我搞清楚,会更新答案。

Update2:我是用另一个存储库再次做到的。这次我认为是因为,当我设置存储库并添加远程源时,我做了一个错字并做了这个:

> git add origin git@github.com/.../repo.git

例如,我忘记了'遥远'。这将〜/ .git / config中的全局原点设置为:

[remote "origin"]
    url = git@github.com/.../repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

从配置中删除它会移除全局原点,但不幸的是当我回到我的新仓库并使用'git add。'时,它不仅会添加我的仓库中的每个文件和目录,但显然我的仓库之外的所有内容都不是在我的全球.gitignore中:

prompt:~/bin/Projects/Haskell/Courses/Stanford$ git remote -v
prompt:>~/bin/Projects/Haskell/Courses/Stanford$ git remote add origin git@github.com:byrongibson/stanford-fall2011-cs240h.git
prompt:>~/bin/Projects/Haskell/Courses/Stanford$ git remote -v
origin  git@github.com:byrongibson/stanford-fall2011-cs240h.git (fetch)
origin  git@github.com:byrongibson/stanford-fall2011-cs240h.git (push)
prompt:>~/bin/Projects/Haskell/Courses/Stanford$ git add .
prompt:>~/bin/Projects/Haskell/Courses/Stanford$ ls -al
total 12
drwxr-xr-x 3 byron byron 4096 2011-09-26 18:19 ./
drwxr-xr-x 3 byron byron 4096 2011-09-26 18:19 ../
drwxr-xr-x 2 byron byron 4096 2011-09-26 18:09 Lectures/
prompt:>~/bin/Projects/Haskell/Courses/Stanford$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   Lectures/basics1-slides.html
#   new file:   Lectures/basics1.html
#   new file:   Lectures/basics1.md
#   new file:   ../../../../btccx/btc.cx/README
#   new file:   ../../../../btccx/btc.cx/README.md
#
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   ../../../../../.gitconfig
#   modified:   ../../../../../.profile
#   modified:   ../../../../../Downloads/Keys/chromiumppa_key.html
#   modified:   ../../../../../Downloads/Keys/chromiumppa_key.pub
#   modified:   ../../../../../Downloads/Keys/linux_signing_key.pub
#   modified:   ../../../../../Downloads/Keys/tor-key-install.sh
#   deleted:    ../../../../btccx/btc.cx/README
#   deleted:    ../../../../btccx/btc.cx/README.md
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   ../../../../../.FBReader/
#   ../../../../../.ICEauthority
#   ../../../../../.Skype/
#   ../../../../../.SpiderOak/
.
.
.
#   ../../../../../Downloads/xmonad-ubuntu.html
#   ../../../../../Downloads/xmonad-ubuntu_files/
#   ../../../../../Dropbox/
#   ../../../../../Music/
#   ../../../../../Pictures/
#   ../../../../../SpiderOak/
#   ../../../../../Ubuntu One/
#   ../../../../../Videos/
#   ../../../../Archive/
#   ../../../../Clients/
#   ../../../../CryptoCurrency/
#   ../../../../Databases/
#   ../../../../Git/
#   ../../../../Go/
#   ../../../../Google/
#   ../../../../Hosts/
#   ../../../99-scala-problems/
#   ../../LYaH/
#   ../../RWH/

2 个答案:

答案 0 :(得分:5)

如果在git存储库外运行git remote -v,通常会出现以下错误:

$ git remote -v
fatal: Not a git repository (or any of the parent directories): .git

我猜想发生的事情是你在某个时刻意外地在主目录中运行git init,这可以解释你所看到的内容。如果您运行:

git rev-parse --show-toplevel

这应该显示您实际所在的git存储库的顶级。

答案 1 :(得分:1)

解决方案:为了澄清上述说明:我忘了先在新项目目录中运行' git init '。因此,运行' git add。',' git remote add origin repo.git '(甚至是拼写错误' git add origin repo.git ')在没有git repo的目录中,将恢复为全局应用命令,因此 git status 中的所有父目录和其他目录都会产生。

运行' git init ',然后' git remote add origin repo.git '修复上述所有内容。