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

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

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

  1. (master)
  2. $ git checkout feature/my-third-branch
  3. Switched to a new branch 'feature/my-third-branch'
  4. branch 'feature/my-third-branch' set up to track 'origin/feature/my-third-branch'.
  5. (feature/my-third-branch)
  6. $ cat .secondhiddenfolder/thirdfile.txt # show file in branch triggering error
  7. this is my third file
  8. (feature/my-third-branch)
  9. $ git checkout my-first-branch
  10. Switched to a new branch 'my-first-branch'
  11. branch 'my-first-branch' set up to track 'origin/my-first-branch'.
  12. (my-first-branch)
  13. $ cat .hiddenfolder/file.txt # show file in branch that doesn't trigger error
  14. this is the contents of file in hidden folder
  15. (my-first-branch)
  16. $ git checkout my-second-branch # switch to a neutral branch
  17. Switched to a new branch 'my-second-branch'
  18. branch 'my-second-branch' set up to track 'origin/my-second-branch'.
  19. (my-second-branch)
  20. $ git show my-first-branch:.hiddenfolder/file.txt # 'git show' from branch without slash works
  21. this is the contents of file in hidden folder
  22. (my-second-branch)
  23. $ git show feature/my-third-branch:.secondhiddenfolder/thirdfile.txt # 'git show' from branch with slash generates error ...
  24. fatal: ambiguous argument 'feature\my-third-branch;.secondhiddenfolder\thirdfile.txt': unknown revision or path not in the working tree.
  25. Use '--' to separate paths from revisions, like this:
  26. 'git <command> [<revision>...] -- [<file>...]'
  27. (my-second-branch)
  28. $ git show 'feature/my-third-branch:.secondhiddenfolder/thirdfile.txt' # ... even with single qutoes ...
  29. fatal: ambiguous argument 'feature\my-third-branch;.secondhiddenfolder\thirdfile.txt': unknown revision or path not in the working tree.
  30. Use '--' to separate paths from revisions, like this:
  31. 'git <command> [<revision>...] -- [<file>...]'
  32. (my-second-branch)
  33. $ git show "feature/my-third-branch:.secondhiddenfolder/thirdfile.txt" # ... and double quotes.
  34. fatal: ambiguous argument 'feature\my-third-branch;.secondhiddenfolder\thirdfile.txt': unknown revision or path not in the working tree.
  35. Use '--' to separate paths from revisions, like this:
  36. 'git <command> [<revision>...] -- [<file>...]'
  37. (my-second-branch)
  38. $ git --version
  39. 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中给出的路径名

  1. (my-second-branch)
  2. $ MSYS_NO_PATHCONV=1
  3. (my-second-branch)
  4. $ git show feature/my-third-branch:.secondhiddenfolder/thirdfile.txt
  5. fatal: ambiguous argument 'feature\my-third-branch;.secondhiddenfolder\thirdfile.txt': unknown revision or path not in the working tree.
  6. Use '--' to separate paths from revisions, like this:
  7. 'git <command> [<revision>...] -- [<file>...]'
  8. (my-second-branch)
  9. $ MSYS2_ARG_CONV_EXCL="*"
  10. (my-second-branch)
  11. $ git show feature/my-third-branch:.secondhiddenfolder/thirdfile.txt
  12. fatal: ambiguous argument 'feature\my-third-branch;.secondhiddenfolder\thirdfile.txt': unknown revision or path not in the working tree.
  13. Use '--' to separate paths from revisions, like this:
  14. 'git <command> [<revision>...] -- [<file>...]'
  15. (my-second-branch)
  16. $

编辑2

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

  1. (my-second-branch)
  2. $ git show feature/my-third-branch://.secondhiddenfolder/thirdfile.txt # https://stackoverflow.com/a/14189687/8469997
  3. fatal: path '//.secondhiddenfolder/thirdfile.txt' does not exist in 'feature/my-third-branch'
  4. (my-second-branch)
  5. $ git show 'feature/my-third-branch://.secondhiddenfolder/thirdfile.txt' # https://stackoverflow.com/a/14189687/8469997
  6. fatal: path '//.secondhiddenfolder/thirdfile.txt' does not exist in 'feature/my-third-branch'
  7. (my-second-branch)
  8. $

abithluo

abithluo1#

最终编辑和解决方案

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

  1. $ MSYS_NO_PATHCONV=1 # set variable without export
  2. (my-second-branch)
  3. $ git show feature/my-third-branch:.secondhiddenfolder/thirdfile.txt # https://stackoverflow.com/a/65570275/846999
  4. fatal: ambiguous argument 'feature\my-third-branch;.secondhiddenfolder\thirdfile.txt': unknown revision or path not in the working tree.
  5. Use '--' to separate paths from revisions, like this:
  6. 'git <command> [<revision>...] -- [<file>...]'
  7. (my-second-branch)
  8. $ export MSYS_NO_PATHCONV=1 # set variable but with export
  9. (my-second-branch)
  10. $ git show feature/my-third-branch:.secondhiddenfolder/thirdfile.txt # https://stackoverflow.com/a/65570275/846999 # we have a winner
  11. this is my third file
  12. (my-second-branch)
  13. $

字符串

展开查看全部

相关问题