Git PathSpec Issue on Git Stash



当我运行其新命令的新版本2.13.0.windows.1时,stash -p -- {pathspec}

git stash -p -- AB.Dir1/Dir2/DestinationHierarchyCreator.cs

它报告错误

错误:路径规范"AB。Dir1/Dir2/DestinationHierarchyCreator.cs' 与 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路径规范必须相对于存储库根目录(顶部)——而不是相对于您当前的工作目录。

由于git status("与许多其他 Git 命令不同")显示路径"如果您在子目录中工作,则相对于当前目录",这似乎容易混淆。

因此,如果您当前的工作目录是~/dev/git_project_root/subdir,则需要使用:

git stash -p -- subdir/AB.Dir1/Dir2/DestinationHierarchyCreator.cs

(通配符git stash -p -- *.cs起作用,因为它匹配根目录下所有修改的 *.cs 文件 - 可能你只有一个。

我刚刚在 Windows 上尝试过:它适用于没有 '.' 的普通文件夹

C:Usersvoncdatagitgit>git st
On branch master
Your branch is up-to-date with 'origin/master'.
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:   Documentation/blame-options.txt
C:Usersvoncdatagitgit>git stash -- Documentationblame-options.txt
Saved working directory and index state WIP on master: b14f27f91 Tenth batch for 2.13

即使在 bash 会话中,使用 -p,它仍然有效

vonc@bvonc MINGW64 ~/data/git/git (master)
$ git stash -p -- Documentation/blame-options.txt
diff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt
index dc41957af..96a5b1b4a 100644
--- a/Documentation/blame-options.txt
+++ b/Documentation/blame-options.txt
@@ -1,7 +1,7 @@
-b::
Show blank SHA-1 for boundary commits.  This can also
be controlled via the `blame.blankboundary` config option.
-
+sss
--root::
Do not treat root commits as boundaries.  This can also be
controlled via the `blame.showRoot` config option.
Stash this hunk [y,n,q,a,d,/,e,?]? y
Saved working directory and index state WIP on master: b14f27f91 Tenth batch for 2.13

在带有"."的文件夹上:

vonc@bvonc MINGW64 ~/data/git/git (master)
$ git stash -p -- a.b/c
error: pathspec 'a.b/c' did not match any file(s) known to git.
Did you forget to 'git add'?

所以这可能是一个可能的问题。


注意,在 Git 2.29(2020 年第 4 季度)中,不再有"Show blank SHA-1 for boundary commits":一些面向最终用户的消息已更新为与哈希算法无关。

参见提交 4279000 (2020 年 8 月 13 日) 由 Junio C Hamano (gitster).
(由 Junio C Hamano --gitster-- 合并于 提交 2a978f8,2020 年 8 月 19 日)

messages:避免在面向最终用户的消息中使用 SHA-1

当我们指的是面向最终用户的消息中的(十六进制)对象名称时,仍然很少提到 SHA-1.
重写它们。

我希望这主要是 s/SHA-1/对象名称/,但需要改写一些消息以保持结果可读。

然后新的错误消息将是:

Do not show object names of boundary commits