git show results in fatal:当分支包含正斜杠(/)时,不明确的参数未知修订版或路径不在工作树中

xzlaal3s  于 2023-08-01  发布在  Git
关注(0)|答案(1)|浏览(148)

我创建了一个名为“feature/my-third-branch”的分支,并创建了一个包含简单文本文件的隐藏文件夹。如果我切换到另一个分支并尝试使用“git show”查看这个文件,我会得到一个错误。如果我重复“git show”到另一个分支中的另一个隐藏文件夹,没有斜杠,它可以正常工作。

(master)
$ git checkout feature/my-third-branch
Switched to a new branch 'feature/my-third-branch'
branch 'feature/my-third-branch' set up to track 'origin/feature/my-third-branch'.

(feature/my-third-branch)
$ cat .secondhiddenfolder/thirdfile.txt # show file in branch triggering error
this is my third file

(feature/my-third-branch)
$ git checkout my-first-branch
Switched to a new branch 'my-first-branch'
branch 'my-first-branch' set up to track 'origin/my-first-branch'.

(my-first-branch)
$ cat .hiddenfolder/file.txt # show file in branch that doesn't trigger error
this is the contents of file in hidden folder

(my-first-branch)
$ git checkout my-second-branch # switch to a neutral branch
Switched to a new branch 'my-second-branch'
branch 'my-second-branch' set up to track 'origin/my-second-branch'.

(my-second-branch)
$ git show my-first-branch:.hiddenfolder/file.txt # 'git show' from branch without slash works
this is the contents of file in hidden folder

(my-second-branch)
$ git show feature/my-third-branch:.secondhiddenfolder/thirdfile.txt # 'git show' from branch with slash generates error ...
fatal: ambiguous argument 'feature\my-third-branch;.secondhiddenfolder\thirdfile.txt': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

(my-second-branch)
$ git show 'feature/my-third-branch:.secondhiddenfolder/thirdfile.txt' # ... even with single qutoes ...
fatal: ambiguous argument 'feature\my-third-branch;.secondhiddenfolder\thirdfile.txt': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

(my-second-branch)
$ git show "feature/my-third-branch:.secondhiddenfolder/thirdfile.txt" # ... and double quotes.
fatal: ambiguous argument 'feature\my-third-branch;.secondhiddenfolder\thirdfile.txt': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

(my-second-branch)
$ git --version
git version 2.41.0.windows.3

字符串
我在错误输出中注意到的是冒号(:)已经变成了分号(;我试过不同的逃跑方法,但似乎都不管用。

我需要做什么才能让'git show'与名称中包含正斜杠(/)的分支一起使用?
编辑1

以防有人错过了最后一行输出,这是Git for Windows GitBash。不,我还没有尝试过CMD或PowerShell,因为我希望坚持使用GitBash以便于移植到Linux。
我忘了说我试过在CygWin中禁用路径转换。
如何阻止MinGW和MSYS破坏命令行https://stackoverflow.com/a/34386471/8469997中给出的路径名

(my-second-branch)
$ MSYS_NO_PATHCONV=1

(my-second-branch)
$ git show feature/my-third-branch:.secondhiddenfolder/thirdfile.txt
fatal: ambiguous argument 'feature\my-third-branch;.secondhiddenfolder\thirdfile.txt': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

(my-second-branch)
$ MSYS2_ARG_CONV_EXCL="*"

(my-second-branch)
$ git show feature/my-third-branch:.secondhiddenfolder/thirdfile.txt
fatal: ambiguous argument 'feature\my-third-branch;.secondhiddenfolder\thirdfile.txt': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

(my-second-branch)
$

编辑2

使用双斜杠(//)禁用也没有帮助(https://stackoverflow.com/a/14189687/8469997),但会给予不同的错误:

(my-second-branch)
$ git show feature/my-third-branch://.secondhiddenfolder/thirdfile.txt # https://stackoverflow.com/a/14189687/8469997
fatal: path '//.secondhiddenfolder/thirdfile.txt' does not exist in 'feature/my-third-branch'

(my-second-branch)
$ git show 'feature/my-third-branch://.secondhiddenfolder/thirdfile.txt' # https://stackoverflow.com/a/14189687/8469997
fatal: path '//.secondhiddenfolder/thirdfile.txt' does not exist in 'feature/my-third-branch'

(my-second-branch)
$

abithluo

abithluo1#

最终编辑和解决方案

作为一名Windows管理员,导出环境变量的概念对我来说是陌生的(https://stackoverflow.com/a/71711466/8469997),但我还是尝试了一下。

$ MSYS_NO_PATHCONV=1 # set variable without export

(my-second-branch)
$ git show feature/my-third-branch:.secondhiddenfolder/thirdfile.txt # https://stackoverflow.com/a/65570275/846999
fatal: ambiguous argument 'feature\my-third-branch;.secondhiddenfolder\thirdfile.txt': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

(my-second-branch)
$ export MSYS_NO_PATHCONV=1 # set variable but with export

(my-second-branch)
$ git show feature/my-third-branch:.secondhiddenfolder/thirdfile.txt # https://stackoverflow.com/a/65570275/846999 # we have a winner
this is my third file

(my-second-branch)
$

字符串

相关问题