Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal: pathspec 'file.txt' did not match any files, GIT

Tags:

git

I have just started learing GIT. Follow their tutorial.

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:

enter image description here

What I am doing wrong here?

like image 813
Hassan Sardar Avatar asked Nov 25 '13 08:11

Hassan Sardar


Video Answer


5 Answers

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
like image 148
chwarr Avatar answered Sep 18 '22 20:09

chwarr


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.

Currently, you have no tracked files, as you can see from your git status command. In order to track all files from the my-project directory, do a git add my-project/*. This will add all the files from that directory.

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.txt file, which you can afterwards add to git using git add file.txt.

like image 45
Raul Rene Avatar answered Sep 16 '22 20:09

Raul Rene


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

As you can see the command is breaking between View & Controllers because there's a space.

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"
like image 31
mfaani Avatar answered Sep 16 '22 20:09

mfaani


Note: you shouldn't see this particular error message in git 1.9/2.0 (Q1 2014).

See commit 64ed07c by Nguyễn Thái Ngọc Duy (pclouds):

add: don't complain when adding empty project root

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).

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:

$ 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)

like image 32
VonC Avatar answered Sep 19 '22 20:09

VonC


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:

git add file.txt.txt
like image 43
Siddharth Avatar answered Sep 17 '22 20:09

Siddharth