Git PathSpec Issue on Git Stash

◇◆丶佛笑我妖孽 提交于 2019-12-04 10:21:49

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!