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

前端 未结 14 1198
难免孤独
难免孤独 2021-02-04 11:59

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         


        
相关标签:
14条回答
  • 2021-02-04 12:08

    This error is raised because the file you are adding to the repository is not created. First create the file and then add it to the staging area:

    touch filename
    git add filename
    
    0 讨论(0)
  • 2021-02-04 12:10

    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"
    
    0 讨论(0)
  • 2021-02-04 12:15

    I had the same issue as well. Please confirm your file directory. After moving my file to the correct directory it works.

    git output

    0 讨论(0)
  • 2021-02-04 12:16

    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.

    0 讨论(0)
  • 2021-02-04 12:19

    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,

    first create the .txt file and mention the path correctly! let there is

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

    e.g-

    if your file is on the desktop then

    $ git add C:Users/username/Desktop/filename.txt
    
    0 讨论(0)
  • 2021-02-04 12:20

    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 :

    MD <new file>
    

    After that you add :

    git add <new file> 
    
    0 讨论(0)
提交回复
热议问题