解决方案: 最终发现问题所在。愚蠢的用户错误。忘记在新项目目录中先运行 'git init'。因此,在没有 git 仓库的目录中运行 'git add .', 'git remote add origin repo.git'(甚至是错别字 'git add origin repo.git')将会回到全局应用命令,因此在 git status 结果中显示所有父目录和其他目录。
例如,我忘记了“remote”。这将全局初始位置设置为~/.git/config:
我使用 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
例如,我忘记了“remote”。这将全局初始位置设置为~/.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/
中创建了一个.git repo,只是为了存储dotfiles,而你的rev-parse命令现在返回作为结果,无论我在的哪个子目录中。你有什么想法如何将我的子目录中的repos与中的repos取消链接吗? - Kurtosis