简体   繁体   中英

What does the git error mean “pathspec did not match any file(s)”

In a Rails app I realised I had committed a sensitive file config/credentials.yml to the git repo.

In an effort to tidy things up I followed the advice on GitHub and ran

git filter-branch --index-filter 'git rm --cached --ignore-unmatch config/credentials.yml' --prune-empty --tag-name-filter cat -- --all

and then added to gitignore

echo "config/credentials.yml" >> .gitignore

When I try to commit these changes

git add .gitignore
git commit -m "ignored credentials.yml"

I'm getting a message

error: pathspec 'adds credentials.yml to gitignore' did not match any file(s) known to git.

How can I fix this error? Or, how can I undo my changes and safely revert to the git history on my remote?

I think you might've forgotten the step

$ git add .gitignore

before trying to commit, or then you mistyped, when you shoud've given

$ git commit -m "Add credentials.yml to .gitignore"

Process advised is highly dangerous [for the repo contents], so one must be really careful to follow all the steps in detail.

Just give a file path while adding file to git add command, it works for me

$ git add mainFolder/.../file.extension

Note: mainFolder would be the folder inside your repo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM