viatech
viatech

Reputation: 89

fatal: pathspec 'file-name' did not match any files. file name is not a path

I typed on the command line $sudo service postgresql restart before working on my branch and when I made a commit git saved it as a new file called "udo service postgresql restart". This file doesn't have a path, it's the same command I typed.

So I tried :

git reset HEAD udo service postgresql restart

And tried:

git rm udo service postgresql restart

Got this error:

fatal: pathspec 'udo' did not match any files

Also tried:

git checkout sudo service postgresql restart

got this error:

error: pathspec 'service' did not match any file(s) known to git.
error: pathspec 'postgresql' did not match any file(s) known to git.
error: pathspec 'restart' did not match any file(s) known to git.```

Upvotes: 0

Views: 3626

Answers (1)

CodeWizard
CodeWizard

Reputation: 142164

Few options:

  1. If this file was not committed and not part of your project, simply delete it.

  2. If you have a file name with spaces you need to wrap the name with " (double quotes)

  3. If this file was added to the staging area and you wish to remove it:

    git rm --cached "udo service postgresql restart"
    
  4. git restore
    If you are using the latest version of git (>2.25) you can use the git restore command

    enter image description here

Upvotes: 1

Related Questions