我正在运行Windows 7,我有最新版本的git(2.7.2.windows.1)。 我之前使用Windows PowerShell作为git操作的终端,没有任何问题。 最近,我决定改用Git Bash,但我遇到了一个重大问题。
我的项目有一个目录(其中有许多子目录),其名称只是一个下划线。 每当我尝试在该目录中的文件上运行git diff时,我都会收到以下错误:
$ git diff _/css/templates/jquery.tag-editor.css fatal: Invalid object name '_C'.
据我所知,下划线是文件/目录名中完全有效的字符,并且在该目录中选项卡完成工作正常,因此我知道终端可以在其中“看到”。 此外,该项目的其他贡献者,他们都运行OSX,没有这个问题。 当我运行一个简单的git diff而没有指定任何单个文件时,它工作正常,并且愉快地包含下划线目录中任何已更改文件的diff。 它也可以工作,如果我进入下划线目录并从那里运行git diff ,所以我传递给它的路径不包括下划线。
究竟发生了什么阻止我在这些文件上运行git diff ? 当我尝试这样做时,“C”来自错误消息中的哪个位置?
更新
当我运行git checkout -- _/css/templates/jquery.tag-editor.css来丢弃对该文件的更改时,这是我看到的错误:
error: pathspec '_C:/Program Files/Git/css/templates/jquery.tag-editor.css' did not match any file(s) known to git.
C:\Program Files\Git是我的Git安装目录。 显然,部分路径被解释为引用Git安装目录? 是什么导致这种情况发生?
I'm running Windows 7, and I have the latest version of git (2.7.2.windows.1). I previously used Windows PowerShell as my terminal for git operations, with no issues. Recently, I decided to switch to Git Bash, but I'm having one major issue.
My project has a directory (within which are many subdirectories) whose name is simply an underscore. Whenever I try to run git diff on a file within that directory, I get the following error:
$ git diff _/css/templates/jquery.tag-editor.css fatal: Invalid object name '_C'.
As far as I know, an underscore is a perfectly valid character in a file/directory name, and tab completion works fine within that directory, so I know the terminal can "see" inside it. Additionally, other contributors to the project, all of them running OSX, do not have this problem. And when I run a simple git diff, without specifying any single file, it works fine, and happily includes the diff for any changed files within the underscore directory. It also works if I cd into the underscore directory and run the git diff from there, so that the path I pass to it does not include the underscore.
What exactly is happening here to prevent me from running git diff on these files? And where does the "C" come from in the error message when I try to do so?
Update
When I run git checkout -- _/css/templates/jquery.tag-editor.css to discard the changes to that file, this is the error I see:
error: pathspec '_C:/Program Files/Git/css/templates/jquery.tag-editor.css' did not match any file(s) known to git.
C:\Program Files\Git is directory of my Git installation. So apparently part of the path is being interpreted as referring to the Git installation directory? Again, what is causing this to happen?
最满意答案
您遇到的问题基于MinGW / Msys2的Posix Path转换 。
在git-bash上尝试加倍斜杠: git diff _//css/templates/jquery.tag-editor.css或使用反斜杠(需要在git-bash中转义): git diff _\\css\\templates\\jquery.tag-editor.css或prepend MSYS_NO_PATHCONV=1 : MSYS_NO_PATHCONV=1 git diff _/css/templates/jquery.tag-editor.css 在CMD上你应该使用反斜杠而不是斜杠: git diff _\css\templates\jquery.tag-editor.css或者加一个斜杠,就像git-bash一样为了防止转换。
The problems you are experiencing are based on the Posix Path conversions of MinGW/Msys2.
on git-bash try to double a slash: git diff _//css/templates/jquery.tag-editor.css or use backslashes (which need to be escaped in git-bash): git diff _\\css\\templates\\jquery.tag-editor.css or prepend MSYS_NO_PATHCONV=1: MSYS_NO_PATHCONV=1 git diff _/css/templates/jquery.tag-editor.css on CMD you should use a backslash instead of a slash: git diff _\css\templates\jquery.tag-editor.css OR double a slash as for git-bashin order to prevent the conversion.
更多推荐
发布评论