致命:pathspec 'file.txt' 不匹配任何文件,GIT
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20188229/
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
Fatal: pathspec 'file.txt' did not match any files, GIT
提问by Hassan Sardar
I have just started learing GIT. Follow their tutorial.
我刚刚开始学习 GIT。按照他们的教程。
Now at the very beginning I got stuck with this error:
现在一开始我就遇到了这个错误:
Fatal: pathspec 'file.txt' did not match any files.
Here is the screenshot of my procedure and commands:
这是我的程序和命令的屏幕截图:
What I am doing wrong here?
我在这里做错了什么?
回答by chwarr
The files don't exist, so they cannot be added. Make sure the files have been created first.
文件不存在,因此无法添加。确保首先创建了文件。
D:\temp\hi>git init
Initialized empty Git repository in D:/temp/hi/.git/
D:\temp\hi>dir
Volume in drive D is Data
Volume Serial Number is 744F-7845
Directory of D:\temp\hi
2013-11-25 12:59 AM <DIR> .
2013-11-25 12:59 AM <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 1,331,387,256,832 bytes free
D:\temp\hi>git add hi.txt
fatal: pathspec 'hi.txt' did not match any files
D:\temp\hi>echo hello > hi.txt
D:\temp\hi>git add hi.txt
D:\temp\hi>dir
Volume in drive D is Data
Volume Serial Number is 744F-7845
Directory of D:\temp\hi
2013-11-25 12:59 AM <DIR> .
2013-11-25 12:59 AM <DIR> ..
2013-11-25 12:59 AM 8 hi.txt
1 File(s) 8 bytes
2 Dir(s) 1,331,387,256,832 bytes free
回答by Raul Rene
In order to add a file to git it has to exist. git add
does not create a file, but tells git to add it to the current branch you are on and track it.
为了将文件添加到 git,它必须存在。git add
不创建文件,而是告诉 git 将它添加到您所在的当前分支并跟踪它。
Currently, you have no tracked files, as you can see from your git status
command. In order to track all files from the my-projectdirectory, do a git add my-project/*
. This will add all the files from that directory.
当前,您没有跟踪文件,正如您从git status
命令中看到的那样。为了跟踪my-project目录中的所有文件,请执行git add my-project/*
. 这将添加该目录中的所有文件。
Next, if you do not have the desired file.txt, just create a text file and run git status
. It should show you that you have an untracked file.txtfile, which you can afterwards add to git using git add file.txt
.
接下来,如果您没有所需的file.txt,只需创建一个文本文件并运行git status
. 它应该显示您有一个未跟踪的file.txt文件,您可以随后使用git add file.txt
.
回答by VonC
Note: you shouldn't see this particular error message in git 1.9/2.0 (Q1 2014).
注意:您不应在 git 1.9/2.0(2014 年第一季度)中看到此特定错误消息。
See commit 64ed07cby Nguy?n Thái Ng?c Duy (pclouds
):
见提交64ed07c通过?Nguyň泰伍Ç维战(? )pclouds
:
add
: don't complain when adding empty project root
add
: 添加空项目根目录时不要抱怨
This behavior was added in 07d7bed(add
: don't complain when adding
empty project root - 2009-04-28, git 1.6.3.2)
then broken by 84b8b5d(remove match_pathspec()
in favor of match_pathspec_depth()
- 2013-07-14, git 1.8.5).
此行为是在07d7bed中添加的(add
:添加空项目根目录时不要抱怨 - 2009-04-28, git 1.6.3.2)
然后被84b8b5d打破(删除match_pathspec()
支持match_pathspec_depth()
- 2013-07-14, git 1.8.5) .
Reinstate it.
恢复它。
The idea is:
这个想法是:
We try to warn the user if one of their pathspecs caused no matches, as it may have been a typo. However, we disable the warning if the pathspec points to an existing file, since that means it is not a typo but simply an empty directory.
Unfortunately, the
file_exists()
test was broken for one special case: the pathspec of the project root is just "".
This patch detects this special case and acts as if the file exists (which it must, since it is the project root).The user-visible effect is that this:
如果他们的路径规范之一导致没有匹配,我们会尝试警告用户,因为它可能是一个错字。但是,如果 pathspec 指向现有文件,我们会禁用警告,因为这意味着它不是拼写错误而只是一个空目录。
不幸的是,
file_exists()
测试在一种特殊情况下被破坏:项目根目录的路径规范只是“”。
该补丁检测到这种特殊情况并表现为文件存在(它必须存在,因为它是项目根)。用户可见的效果是:
$ mkdir repo && cd repo && git init && git add .
used to complain like:
曾经抱怨过:
fatal: pathspec '' did not match any files
but now is a silent no-op.
但现在是一个无声的无操作。
It is again a silent no-op in upcoming git 1.9/2.0 (Q1 2014)
在即将发布的 git 1.9/2.0(2014 年第一季度)中,这又是一个无声的空操作
回答by Siddharth
I had the same problem because the file name is already appended with .txt and you are adding an extra .txt explicitly. You can try with this:
我遇到了同样的问题,因为文件名已经附加了 .txt 并且您显式添加了一个额外的 .txt。你可以试试这个:
git add file.txt.txt
回答by Honey
I was doing:
我在做:
git add AppName/View Controllers/Sections/Devices/DeviceContainerViewController.swift
But was getting the following error:
但是收到以下错误:
fatal: pathspec 'AppName/View' did not match any files
致命:pathspec 'AppName/View' 不匹配任何文件
As you can see it's breaking between View & Controllers because there's a space.
正如你所看到的,它在 View 和 Controllers 之间中断,因为有一个空间。
I just had to wrap my path into double quotes. It's not normally necessary, but when you have spaces you need to.
我只需要将我的路径用双引号括起来。这通常不是必需的,但是当您有空间时,您需要这样做。
git add "AppName/View Controllers/Sections/Devices/DeviceContainerViewController.swift"
回答by Amina
In order to add a file to git it has to exist. git add
does not create a file, but tells git to add it to the current branch you are on and track it. So you should create a new file in the command line :
为了将文件添加到 git,它必须存在。git add
不创建文件,而是告诉 git 将它添加到您所在的当前分支并跟踪它。所以你应该在命令行中创建一个新文件:
MD <new file>
After that you add :
之后你添加:
git add <new file>
回答by Ashita Gaur
The file is not matched because git add
creates your file in the root directory but it actually does not create a file, but tells git to add it to the current branch you are on (adds files from the working directory to the staging area) and track it with git status
command. So,
该文件不匹配,因为git add
在根目录中创建了您的文件,但实际上并没有创建文件,而是告诉 git 将其添加到您所在的当前分支(将工作目录中的文件添加到暂存区)并跟踪它与git status
命令。所以,
first create the .txt file and mention the path correctly!let there is
首先创建 .txt 文件并正确提及路径!让有
$ git add path/filename.txt
(Not for it only, for any git command for a change in staging area write the whole path of the filename with forwarding slash after the command )
(不仅如此,对于任何更改暂存区的 git 命令,请在命令后写入带有正斜杠的文件名的整个路径)
e.g-
例如-
if your file is on the desktop then
如果您的文件在桌面上,那么
$ git add C:Users/username/Desktop/filename.txt
回答by androminor
I was also stuck over this. The solution is : a) Make any txt file first let's say " Readme.txt "
我也被困在这个问题上。解决方案是:a)首先制作任何txt文件,让我们说“Readme.txt”
b) Copy this text file to you local git repo(folder) eg- C:/store
b) 将此文本文件复制到本地 git repo(folder) eg-C:/store
c) Go to windows command prompt if you are on windows (type " cmd " on search bar when you click on window button )
c) 如果您在 windows 上,请转到 windows 命令提示符(单击窗口按钮时,在搜索栏上键入“cmd”)
d) go to your local git repo. type ** echo hello > Readme.txt** ---> C:\admin\store>echo hello > Readme.txt
d) 去你当地的 git 仓库。输入 ** echo hello > Readme.txt** ---> C:\admin\store>echo hello > Readme.txt
echo hello is a dos command which shows output status text to the screen or a file.
echo hello 是一个 dos 命令,它向屏幕或文件显示输出状态文本。
回答by Suresh Dooly
Here you go! Very simple. Need to place the .txt file manually in the pwd mentioned folder...
干得好!很简单。需要将 .txt 文件手动放置在 pwd 提到的文件夹中...
suumapat@SUUMAPAT-IN MINGW64 ~/newproject (master) $ git add abc.txt fatal: pathspec 'abc.txt' did not match any files
suumapat@SUUMAPAT-IN MINGW64 ~/newproject (master) $ git add abc.txt fatal: pathspec 'abc.txt' 没有匹配任何文件
suumapat@SUUMAPAT-IN MINGW64 ~/newproject (master) $ dir
suumapat@SUUMAPAT-IN MINGW64 ~/newproject (master) $ dir
suumapat@SUUMAPAT-IN MINGW64 ~/newproject (master) $ pwd /c/Users/suumapat/newproject
suumapat@SUUMAPAT-IN MINGW64 ~/newproject (master) $ pwd /c/Users/suumapat/newproject
suumapat@SUUMAPAT-IN MINGW64 ~/newproject (master) $ dir abc.txt
suumapat@SUUMAPAT-IN MINGW64 ~/newproject (master) $ dir abc.txt
suumapat@SUUMAPAT-IN MINGW64 ~/newproject (master) $ git add abc.txt
suumapat@SUUMAPAT-IN MINGW64 ~/newproject (master) $ git add abc.txt
回答by David Hash
I was having the same issue but with the Windows file system. Here was my solution that worked.
我遇到了同样的问题,但使用的是 Windows 文件系统。这是我的解决方案。
from the git project directory. Here is exactly what was displayed with the current directory.
从 git 项目目录。这正是当前目录显示的内容。
D:\Projects\ReactNative\project>git add "scr/\components/\validate.js"
D:\Projects\ReactNative\project>git add "scr/\components/\validate.js"
The file being entered into git was validate.js. It was in a directory under the project. That directory was src\components.
输入到 git 中的文件是 validate.js。它在项目下的目录中。该目录是 src\components。