Skip to content

Pathspec 做不 Match

错误信息

                fatal: pathspec 'filename' 做不 match 任何 files
              

快速摘要

你 referenced file 那个 Git cannot 查找 — 它做不 exist in 工作 directory or 是不 tracked.

为什么发生

  • Typo in filename

  • file 做不 exist in current directory

  • file 是 ignored 通过 .gitignore

  • 你是 in 错误 directory

最小示例

✗ 错误代码
git add readme.md  # fatal: pathspec 'readme.md' did not match
✓ 修复代码
git add README.md  # correct capitalization

file 是 named README.md (uppercase), 不 readme.md. Filenames 是情况-sensitive — fix spelling.

如何诊断

  • 检查 file exists 使用 ls or dir

  • 验证 spelling and path

  • 运行 git 状态到 see tracked files

  • 检查如果 file matches .gitignore 模式

如何修复

  • 正确 filename spelling or path

  • 导航到正确 directory 使用 CD

  • 如果 file 是 ignored, use git 添加 -f 到 force-添加它

  • 创建 file 如果它做不 exist

如何预防

  • Use tab-completion for filenames 到 avoid typos

  • 验证 file paths 使用 ls 之前运行 git commands

相关资源

相关术语

相关课程

← 返回语言