2017-05-11 36 views
4

當我運行其新的命令stash -p -- {pathspec}作爲的Git PathSpec問題

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

它報告錯誤的新版本2.13.0.windows.1

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選項的理解錯了,或者是我的pathspec的處理不正確的個人文件(S)或其他什麼東西?

+1

奇怪。我在https://github.com/git-for-windows/git/issues?utf8=%E2%9C%93&q=stash%20is%3Aissue%20或http:// marc上看不到任何問題。 info /?l = git&w = 4&r = 1&s = stash + match&q = b – VonC

+0

@VonC我認爲這是一個用戶錯誤,在發現git錯誤之前。 – OmegaMan

回答

2

剛剛遇到同樣的問題。看來git stash pathspecs必須是相對於存儲庫根目錄(頂部) - 而不是你當前的工作目錄。

由於git status(「不像許多其他Git命令」)顯示路徑「relative to the current directory如果您正在子目錄中工作」,這似乎很容易混淆。

因此,如果您當前的工作目錄,比如〜的/ dev/git_project_root /子目錄,你需要使用:

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

(通配符git stash -p -- *.cs的工作,因爲它匹配所有修改*的.cs文件在你的根目錄下 - 可能你只有那一個。)

+0

只是想說我剛剛遇到了這個(在Linux上)。你知道這是一個已知的問題,還是它是一個有意圖的「特徵」? – bow

+0

我猜這是故意的還是疏忽的。但這並不完全清楚。 ['pathspec' docs](https://git-scm.com/docs/gitglossary#gitglossary-aiddefpathspecapathspec)說:「請參閱每個命令的文檔以瞭解路徑是否與當前目錄或頂層相關。」但是['git stash push' docs](https://git-scm.com/docs/git-stash#git-stash-push-p--patch-k--no-keep-index-u-- include-untracked-a - all-q - quiet -m - messageltmessagegt - ltpathspecgt82308203)不說這個命令是如何處理pathspecs的。 – medmunds

1

我只是想在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,它仍然可以工作

[email protected] 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 

在有 '.' 的文件夾:

[email protected] 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'? 

所以這可能是一個可能的問題。

+0

對於我來說,子文件夾的名稱中有一個'.',然後有一個子文件夾。 'AB.Dir1/Dir2中/'。我會嘗試在一個子文件夾上做到這一點。 – OmegaMan

+0

@OmegaMan我同意。我編輯了答案來說明一個帶有'.'的文件夾是如何產生問題的。 – VonC

+0

其他事情正在發生。我試圖從沒有'.'問題的較低目錄存儲並仍然收到相同的錯誤。我會繼續調查。 – OmegaMan