3

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?

Andy Harvey
  • 12,333
  • 17
  • 93
  • 185
  • Might this help? [http://stackoverflow.com/questions/5989592/git-cannot-checkout-branch-error-pathspec-did-not-match-any-files-kn](http://stackoverflow.com/questions/5989592/git-cannot-checkout-branch-error-pathspec-did-not-match-any-files-kn) – Magicmarkker Dec 11 '12 at 16:46

2 Answers2

3

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.

eis
  • 51,991
  • 13
  • 150
  • 199
  • thanks eis. I had already run `git add .gitignore`. Are there any other steps i can take to resolve this? I realize this is a dangerous process, and am reluctant to take any more steps on my own without advice – Andy Harvey Dec 11 '12 at 17:13
  • grateful for your advice on this, if I use `git reset HEAD --hard` to reset local from my remote repo, will this undo these changes I've made to the local git. Or does the routine above run deeper than that! Apologies, still trying to get my head around this. – Andy Harvey Dec 12 '12 at 03:28
0

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

iMRahib
  • 532
  • 4
  • 4