1

I am trying to reset two files in my repository back to HEAD state using git, but I receive the following error:

error: pathspec 'package-lock.json' did not match any file(s) known to git.

I am extremely confused because when I run git status the files show up as having been modified, so they're definitely there. I found a blog post that suggests the file tree may have been changed but I haven't changed any file or folder names or positions.

Please advise!

code reproduction:

  • git status returns package-lock.json and src/react-app-env.d.ts
  • git reset HEAD package-lock.json src/react-app-env.d.ts runs with no issue and unstages the two files
  • git checkout HEAD -- src/react-app-env.d.ts package-lock.json gives the following error:
    error: pathspec 'src/react-app-env.d.ts' did not match any file(s) known to git.
    error: pathspec 'package-lock.json' did not match any file(s) known to git.
    
Holger Just
  • 52,918
  • 14
  • 115
  • 123
pea-sea
  • 169
  • 1
  • 1
  • 9

1 Answers1

0

You're files haven't been commited in order for the checkout command to know at which state to put them when you try to move them to HEAD. First commit them and then the two commands will run (keep in mind that they do somewhat different things).

Side note: in the new versions of git (git 2.23) there is a new command: git restore <file> which discards changes in the working directory and there is also git restore --staged <file> which unstaged a file. Read about it here.

mnestorov
  • 4,116
  • 2
  • 14
  • 24