git 致命:路径规范“README.txt”与任何文件都不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47877925/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:00:34  来源:igfitidea点击:

fatal: pathspec 'README.txt' did not match any files

git

提问by Reena Verma

Really getting stuck on this one. I've googled a lot and can't figure out what I've done wrong...

真的被这个卡住了。我用谷歌搜索了很多,无法弄清楚我做错了什么......

I'm trying to create a new file, via the git add README.txtcommand in terminal...

我正在尝试通过git add README.txt终端中的命令创建一个新文件...

(So far I've created a new folder Fundamentals. Created a sub-folder git-practice. And created a git repo via git initcommand)

(到目前为止,我已经创建了一个新文件夹Fundamentals。创建了一个子文件夹git-practice。并通过git init命令创建了一个 git repo )

However, when I try and add a file in fundamentals/git-practice, i get the following error..

但是,当我尝试在中添加文件时fundamentals/git-practice,出现以下错误..

fatal: pathspec 'README.txt' did not match any files

Not sure what I'm doing wrong.. everything seems to make sense. Here's the code:

不知道我做错了什么......一切似乎都有道理。这是代码:

Reenas-MBP:~ reenaverma$ cd ~

Reenas-MBP:~ reenaverma$ ls
72.png          GitHub          flask-workshop
Applications        Library         fundamentals
Creative Cloud Files    Movies          funny_things
Desktop         Music           get-pip.py
Documents       Pictures        world
Downloads       Public          wwlc
Dropbox         Retrieved Contents

Reenas-MBP:~ reenaverma$ cd fundamentals

Reenas-MBP:fundamentals reenaverma$ ls
git-practice

Reenas-MBP:fundamentals reenaverma$ cd git-practice

Reenas-MBP:git-practice reenaverma$ ls -a
.   ..  .git

Reenas-MBP:git-practice reenaverma$ pwd
/Users/reenaverma/fundamentals/git-practice

Reenas-MBP:git-practice reenaverma$ git add README.txt
fatal: pathspec 'README.txt' did not match any files

Reenas-MBP:git-practice reenaverma$ 

采纳答案by Code-Apprentice

fatal: pathspec 'README.txt' did not match any files

致命:路径规范“README.txt”与任何文件都不匹配

You get this error because there is no file named README.txtin the current directory. Git is in the business of managing files that you create with other programs, usually a text editor or IDE. git addonly adds the file to the index. It does not create any files directly. You need to use another tool to do so. Use your favorite text editor (I suggest Notepad++, Sublime Text 3, or Atom) and create a file with some text.

您收到此错误是因为README.txt当前目录中没有指定的文件。Git 负责管理您使用其他程序(通常是文本编辑器或 IDE)创建的文件。git add只将文件添加到索引中。它不直接创建任何文件。您需要使用其他工具来执行此操作。使用您最喜欢的文本编辑器(我建议使用 Notepad++、Sublime Text 3 或 Atom)并创建一个包含一些文本的文件。

回答by eis

I'm trying to create a new file, via the 'git add README.txt' command in terminal...

我正在尝试通过终端中的“git add README.txt”命令创建一个新文件...

git adddoes not create a new file. It adds an existing file to be indexed by git. You'll need to create the file first.

git add不创建新文件。它添加了一个由 git 索引的现有文件。您需要先创建文件。

回答by Dream

The following code works for me

以下代码对我有用

git add README.txt

回答by Dream

I do following this command (windows10) in terminal and everthing is working

我在终端中执行此命令(windows10)并且一切正常

回答by Rad_Lasad

Just type in your terminal (e.g. in git bash):

只需在您的终端中输入(例如在 git bash 中):

git >> README.md
git add README.md

回答by Pushpinder Singh

Try doing the same with cloning your repository locally and " git commit data " into that. finally " git push -u origin master "

尝试在本地克隆您的存储库并将“ git commit data ”放入其中。最后“ git push -u origin master ”

If that may help

如果那可能有帮助

回答by Abuimam

I had the same problem and after typing ls I had git display all the files I had in the folder, then I found that I had saved the readme file as readme.txt.txt. Hence I had to rename the file to readme.txt and then I was able to add it successfully.

我遇到了同样的问题,在输入 ls 后,我让 git 显示文件夹中的所有文件,然后我发现我已将自述文件保存为 readme.txt.txt。因此,我不得不将文件重命名为 readme.txt,然后我才能成功添加它。