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:
What I am doing wrong here?
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
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
.
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"
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 rootThis 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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With