【问题标题】:What does the git error mean "pathspec did not match any file(s)"git错误是什么意思“pathspec不匹配任何文件”
【发布时间】:2012-11-29 06:16:57
【问题描述】:

在 Rails 应用程序中,我意识到我已将敏感文件 config/credentials.yml 提交到 git 存储库。

为了收拾东西,我跟着advice on GitHub跑了

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

然后添加到 gitignore

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

当我尝试提交这些更改时

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

我收到一条消息

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

如何解决此错误?或者,我怎样才能撤消我的更改并安全地恢复到我的遥控器上的 git 历史记录?

【问题讨论】:

标签: ruby-on-rails git github


【解决方案1】:

我想你可能忘记了步骤

$ git add .gitignore

在尝试提交之前,或者你输入错误,当你应该给予时

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

[对于 repo 内容] 建议的过程非常危险,因此必须非常小心地详细执行所有步骤。

【讨论】:

  • 感谢 eis。我已经运行了git add .gitignore。我可以采取任何其他步骤来解决这个问题吗?我意识到这是一个危险的过程,我不愿意在没有建议的情况下自行采取更多步骤
  • 感谢您对此的建议,如果我使用 git reset HEAD --hard 从远程仓库重置本地,这会撤消我对本地 git 所做的这些更改。还是上面的例程比这更深入!抱歉,我仍在努力解决这个问题。
【解决方案2】:

将文件添加到git add命令时只需提供文件路径,它对我有用

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

注意:mainFolder 将是您的仓库中的文件夹

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-09
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 2022-10-12
    • 2013-06-01
    • 1970-01-01
    相关资源
    最近更新 更多