When I run the new version 2.13.0.windows.1 of its new command stash -p -- {pathspec}
as
git stash -p -- AB.Dir1/Dir2/DestinationHierarchyCreator.cs
it reports the error
error: pathspec 'AB.Dir1/Dir2/DestinationHierarchyCreator.cs' did not match any file(s) known to git.
Yet when I do a git status
, where I copied the file from actually, it reports
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
If I go to the directory the files lives in and do git stash -p -- DestinationHierarchyCreator.cs
It fails with the same error.
If I run the command git stash -p -- *.cs
then I can save fragments to the stash.
So is my understanding of the git stash -p
option wrong, or is my handling of the pathspec incorrect for individual file(s) or something else?
Just ran into the same problem. It appears that git stash
pathspecs must be relative to the repository root (top) -- not to your current working dir.
Since git status
("unlike many other Git commands") shows paths "relative to the current directory if you are working in a subdirectory," this seems prone to confusion.
So if your current working directory is, say, ~/dev/git_project_root/subdir, you'd need to use:
git stash -p -- subdir/AB.Dir1/Dir2/DestinationHierarchyCreator.cs
(The wildcard git stash -p -- *.cs
worked because it was matching all modified *.cs files below your root -- and probably you only had that one.)
I just tried it on Windows: it works on a normal folder without '.
'
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
Even in a bash session, and with the -p, it does still work
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
On a folder with '.
':
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'?
So that could be a possible issue.
来源:https://stackoverflow.com/questions/43920234/git-pathspec-issue-on-git-stash