当我运行新版本 2.13.0.windows.1 的新命令时 stash -p -- {pathspec}
as
git stash -p -- AB.Dir1/Dir2/DestinationHierarchyCreator.cs
报错
error: pathspec 'AB.Dir1/Dir2/DestinationHierarchyCreator.cs' did not match any file(s) known to git.
然而,当我执行 git status
时,我从实际复制文件的地方,它报告
Your branch is up-to-date with 'origin/project/develop'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: AB.Dir1/Dir2/DestinationHierarchyCreator.cs
如果我转到文件所在的目录并执行 git stash -p -- DestinationHierarchyCreator.cs
它会失败并出现相同的错误。
如果我运行命令 git stash -p -- *.cs
然后我可以将片段保存到存储中。
那么我对 git stash -p
选项的理解是错误的,还是我对单个文件或其他文件的路径规范的处理不正确?
最佳答案
刚遇到同样的问题。看来 git stash
pathspecs 必须相对于存储库根目录(顶部)——而不是相对于您当前的工作目录。
由于 git status
(“与许多其他 Git 命令不同”)显示路径“relative to the current directory 如果您在子目录中工作,”这似乎容易造成混淆。
因此,如果您当前的工作目录是 ~/dev/git_project_root/subdir,则您需要使用:
git stash -p -- subdir/AB.Dir1/Dir2/DestinationHierarchyCreator.cs
(通配符 git stash -p -- *.cs
之所以有效,是因为它匹配根目录下所有修改过的 *.cs 文件——而且您可能只有那个文件。)
关于Git Stash 上的 Git PathSpec 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43920234/