Git Git Stash 上的 PathSpec 问题
Git PathSpec Issue on Git Stash
当我运行新版本2.13.0.windows.1其新命令stash -p -- {pathspec}
为
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
选项的理解是错误的,还是我对单个文件或其他文件的路径规范的处理不正确?
我刚在 Windows 上试过:它适用于没有“.
”的普通文件夹
C:\Users\vonc\data\git\git>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:\Users\vonc\data\git\git>git stash -- Documentation\blame-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
”:一些面向最终用户的消息已更新为与哈希算法无关。
见commit 4279000 (13 Aug 2020) by Junio C Hamano (gitster
)。
(由 Junio C Hamano -- gitster
-- in commit 2a978f8 合并,2020 年 8 月 19 日)
messages
: avoid SHA-1 in end-user facing messages
There are still a handful mentions of SHA-1 when we meant the (hexadecimal) object names in end-user facing messages.
Rewrite them.
I was hoping that this can mostly be s/SHA-1/object name/, but a few messages needed rephrasing to keep the result readable.
那么新的错误信息将是:
Do not show object names of boundary commits
刚运行遇到同样的问题。看起来 git stash
pathspecs 必须相对于存储库根目录(顶部)——而不是相对于您当前的工作目录。
因为 git status
("unlike many other Git commands") 显示路径“relative to the current directory 如果您在子目录中工作,”这似乎很容易混淆。
因此,如果您当前的工作目录是 ~/dev/git_project_root/subdir,您需要使用:
git stash -p -- subdir/AB.Dir1/Dir2/DestinationHierarchyCreator.cs
(通配符 git stash -p -- *.cs
之所以有效,是因为它匹配根目录下所有修改过的 *.cs 文件——可能您只有那个文件。)
当我运行新版本2.13.0.windows.1其新命令stash -p -- {pathspec}
为
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
选项的理解是错误的,还是我对单个文件或其他文件的路径规范的处理不正确?
我刚在 Windows 上试过:它适用于没有“.
”的普通文件夹
C:\Users\vonc\data\git\git>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:\Users\vonc\data\git\git>git stash -- Documentation\blame-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
”:一些面向最终用户的消息已更新为与哈希算法无关。
见commit 4279000 (13 Aug 2020) by Junio C Hamano (gitster
)。
(由 Junio C Hamano -- gitster
-- in commit 2a978f8 合并,2020 年 8 月 19 日)
messages
: avoid SHA-1 in end-user facing messages
There are still a handful mentions of SHA-1 when we meant the (hexadecimal) object names in end-user facing messages.
Rewrite them.I was hoping that this can mostly be s/SHA-1/object name/, but a few messages needed rephrasing to keep the result readable.
那么新的错误信息将是:
Do not show object names of boundary commits
刚运行遇到同样的问题。看起来 git stash
pathspecs 必须相对于存储库根目录(顶部)——而不是相对于您当前的工作目录。
因为 git status
("unlike many other Git commands") 显示路径“relative to the current directory 如果您在子目录中工作,”这似乎很容易混淆。
因此,如果您当前的工作目录是 ~/dev/git_project_root/subdir,您需要使用:
git stash -p -- subdir/AB.Dir1/Dir2/DestinationHierarchyCreator.cs
(通配符 git stash -p -- *.cs
之所以有效,是因为它匹配根目录下所有修改过的 *.cs 文件——可能您只有那个文件。)