简体   繁体   English

为什么 git 说我的文件在存储库之外?

[英]Why does git say that my file is outside the repository?

Hey guys beginner here how do I upload file into github using git.嘿,初学者,我如何使用 git 将文件上传到 github。

This is my command:这是我的命令:

$ git add C:\Users\Dan\Downloads\filecrdownload
fatal: C:UsersDa: 'C:UsersDan' is outside repository

What did do wrong?做错了什么? How should I fix this?我应该如何解决这个问题?

You can only add the files from a git repo. 您只能从git repo添加文件。

You can use git init to initialize a git repo in the current location. 您可以使用git init初始化当前位置的git repo。 Then you can do git add path_to_your_file 然后你可以做git add path_to_your_file

Assuming you already have a repo set up on Github, you'll need to clone it on your computer. 假设您已经在Github上设置了存储库,则需要在计算机上克隆它。

git clone <url-to-repo>

The url can be found on the front page for your repo: 网址可以在您的仓库的首页上找到: github回购网址

Clone will create a new directory in your filesystem, and you'll want to move your file into there. 克隆将在文件系统中创建一个新目录,您将需要将文件移到该目录中。

Once the file is inside your git directory, you can simply do: 将文件放入git目录后,您只需执行以下操作:

git add filecrdownload
git commit -m "Added filecrdownload"
git push

Which stages filecrdownload , makes a new commit and pushes that commit. 哪个阶段执行filecrdownload ,进行新提交并推送该提交。 You should now see it on Github. 您现在应该在Github上看到它。

There is another scenario where you would see that error message: same path with different case (lower/upercase) 在另一种情况下,您会看到该错误消息:路径相同且大小写不同(小写/大写)

mkdir "c:\repo"
cmd /K "cd c:\repo\"
git init
echo "content" > file.txt
git add C:\repo\file.txt

Note the add C:\\ vs. c:\\ . 注意add C:\\ vs. c:\\

This was reported in git-for-windows/git issue 735 in 2016, was fixed in Git for Windows (fork of Git) 2.16 in 2017 , and is now (Feb. 2019) available with Git 2.21. 问题在2016年的git-for-windows / git问题735中进行了报告, 在2017年的Windows Git(Git分支)2.16中已修复,现在(2019年2月)在Git 2.21中可用。

See commit d8727b3 (18 Jan 2019) by Johannes Schindelin ( dscho ) . 请参阅Johannes Schindelin( dscho )的 commit d8727b3 (2019年1月18日
(Merged by Junio C Hamano -- gitster -- in commit ff09c9e , 05 Feb 2019) (由Junio C gitster - gitster-提交ff09c9e合并 ,2019年2月5日)

abspath_part_inside_repo : respect core.ignoreCase abspath_part_inside_repo :尊重core.ignoreCase

If the file system is case-insensitive, we really must be careful to ignore differences in case only. 如果文件系统不区分大小写,那么我们真的必须小心,仅在区分大小写时才忽略差异。

If anyone gets this on a mac (in my case Big Sur on an M1) on a local, non-bare repo without a remote, and tries to tear their hair out;如果有人在没有遥控器的本地非裸仓库上的 mac(在我的情况下是 M1 上的 Big Sur)上得到这个,并试图撕掉他们的头发; I got this error, and all the other results from here or other searching were either dumb (like expecting everyone to use GitHub) or just wrong.我收到了这个错误,来自这里或其他搜索的所有其他结果要么是愚蠢的(比如期望每个人都使用 GitHub),要么就是错误的。

Since the Windows capital/lowercase drive letter thing does not apply, and the path is DEAD SIMILAR with proper full path AND same capitalization, like /home/me/repo/test.txt would NOT add even though everything LOOKED similar:由于 Windows 大写/小写驱动器号不适用,并且路径与正确的完整路径和相同的大写相同,例如 /home/me/repo/test.txt 不会添加,即使所有内容看起来都相似:

I took a look in .git/config and there was one line我查看了.git/config并且有一行

precomposeunicode = true

Thinking about other replies about character sets etc (who ever works in anything but UTF-8 these days, but still) I changed it on a whim to FALSE考虑有关字符集等的其他回复(这些天谁曾在 UTF-8 之外工作过,但仍然如此)我一时兴起将其更改为FALSE

And it worked!它奏效了! My commit went through!我的提交通过了!

And I thought I'd write this here since it was a fix to something apparently only I have experienced, to avoid being a dumb wise ancient.我想我会在这里写这个,因为它是对显然只有我经历过的事情的修复,以避免成为一个愚蠢的聪明的古代人。

https://xkcd.com/979/ https://xkcd.com/979/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM