gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 11:47:38 25 4
gpt4 key购买 nike

解决方案: 终于意识到问题所在了。愚蠢的用户错误。忘记先在新项目目录中运行“git init”。因此,运行“git add .”、“git remote add origin repo.git”(甚至是拼写错误“git add origin repo.git') 在没有 git 存储库的目录中,将恢复为全局应用命令,因此 git status 结果中的所有父目录和其他目录。


我已经使用 git 一段时间了,但从未遇到过这个问题,不确定发生了什么。简而言之,使用 'git remote add origin git@github.com...' 创建一个跨我整个文件系统的全局远程,而不是仅在当前目录中的本地远程。它甚至会覆盖其他横向目录中的 Remote 。

代码值一千字,任何人都知道这里发生了什么:

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 回到我的新仓库并使用“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 存储库之外运行 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 存储库的顶层。

关于linux - 使用 'git remote add origin' 创建一个全局远程而不是一个本地到当前目录/repo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7369704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com