Git diff在路径下用下划线在文件上失败 [英] Git diff fails on file with underscore in path

查看:147
本文介绍了Git diff在路径下用下划线在文件上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Windows 7,并且拥有最新版本的git(2.7.2.windows.1)。我以前使用Windows PowerShell作为我的git操作终端,没有问题。最近,我决定切换到Git Bash,但我遇到了一个主要问题。



我的项目有一个目录(其中有很多子目录)下划线。每当我尝试在该目录下的文件上运行 git diff 时,出现以下错误:

$ git diff _ / css / templates / jquery.tag-editor.css
fatal:无效的对象名称'_C'。



据我所知,下划线是文件/目录名称中完全有效的字符,并且该目录中的Tab完成工作正常,所以我知道终端可以在其中看到。另外,项目的其他贡献者,他们都运行OSX,没有这个问题。当我运行一个简单的 git diff 时,没有指定任何单个文件,它工作正常,并且愉快地包含下划线目录内任何已更改文件的diff。它也可以工作,如果我 cd 放入下划线目录并从那里运行 git diff ,那么路径I通过它不包括下划线。



这里发生了什么,以防止我在这些上运行 git diff 文件?当我尝试这样做时,错误消息中的C来自哪里?

更新



当我运行 git checkout - _ / css / templates / jquery.tag-editor.css 来放弃对该文件的更改时,这是我看到的错误:



error:pathspec'_C:/ Program Files / Git / css / templates / jquery.tag-editor.css'不匹配任何文件s)已知git。



C:\程序文件\Git 是我的Git安装目录。所以显然,部分路径被解释为指Git安装目录?再次,是什么导致了这种情况发生?

解决方案

您遇到的问题基于 MinGW / Msys2的Posix路径转换


  • 在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 或者double a斜杠为git-bash



为了防止转换。


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?

解决方案

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-bash

in order to prevent the conversion.

这篇关于Git diff在路径下用下划线在文件上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆