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

解决方案:终于意识到问题所在。愚蠢的用户错误。忘记先在新项目目录中运行“git init”。因此,在没有git repo的目录中运行“git add.”、“git remote add origin repo.git”(甚至键入“git add origin repo.git”)将恢复为全局应用该命令,因此git状态中的所有父目录和其他目录都将返回结果。
我使用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$ 

最新消息1:这个问题神秘地消失了。不知道我做了什么或为什么。如果我搞清楚了,会更新答案。
更新2:我又用另一个存储库做了一次。这一次我认为是因为,当我设置存储库并添加远程源代码时,我犯了一个错误,并执行了以下操作:
> git add origin git@github.com/.../repo.git

我忘了带遥控器。将~/.git/config中的全局原点设置为:
[remote "origin"]
    url = git@github.com/.../repo.git
    fetch = +refs/heads/*:refs/remotes/origin/*

从配置中删除它会删除全局源代码,但不幸的是,当我将cd放回新的repo并使用“git add”时,它不仅会添加我的repo中的所有文件和目录,而且显然还会添加不在全局中的repo之外的所有文件和目录。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/


最佳答案:

如果在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存储库的顶层。

公众号