GIT: error: pathspec 'xxx did not match any file(s) known to git

后端 未结 3 1186
予麋鹿
予麋鹿 2021-02-06 13:17

I have some trouble with a git repository of mine and I cant find the error :(

Thing is, I had this repository already in use for a PHP project. everything was fine. The

3条回答
  •  后悔当初
    2021-02-06 14:00

    I often have this problem if something has changed, added files to gitignore or something else. Maybe you have to rebuild the index.

    Updated: added recursive and file param to git rm

    In my case this worked:

    remove cached files (only the paths are removed from the index, not the real files!!!)

    git rm -r --cached .
    

    add all files to the index

    git add .
    

    commit

    git commit -m "hopefully fixed pathspec error"
    

    UPDATE: If this won't work, try the following:

    • Get a new checkout from your repo
    • remove composer, composer.lock, vendor/ from your .gitignore
    • run the above suggestion again
    • move the folders composer, composer.lock, vendor/ outside your repo
    • add and commit, maybe add with -A to add that the files are deleted
    • add composer, composer.lock, vendor/ to your .gitignore and commit
    • move back the folders composer, composer.lock, vendor/ to your repo

    Now it should be gone from the repo and due to your .gitignore, never will be commited again. Hopefully the pathspec error is gone :)

提交回复
热议问题