Andy Harvey
Andy Harvey

Reputation: 12653

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?

Upvotes: 3

Views: 15958

Answers (2)

iMRahib
iMRahib

Reputation: 532

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

Upvotes: 0

eis
eis

Reputation: 53462

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.

Upvotes: 3

Related Questions