windows msys git 和长路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4992577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
msys git and long paths
提问by Jonny Buchanan
I'm trying to use git to more effectively manage working on project which uses CVS for its source control, but I'm having problems add
-ing a file which has a very long path indeed - 276 characters.
我正在尝试使用 git 来更有效地管理使用 CVS 进行源代码控制的项目的工作,但我遇到了问题 -add
文件的路径确实很长 - 276 个字符。
Unfortunately, this file is generated by the custom IDE the tool I'm using is shipped with and it's expected to be there by the tool, so can't be renamed or moved.
不幸的是,此文件是由我正在使用的工具随附的自定义 IDE 生成的,并且预计该工具会在那里,因此无法重命名或移动。
Using the following to try to make this semi-readable:
使用以下内容尝试使其具有半可读性:
<projectpath>
- the path holding all components for this project<hugepath>
- the path from <projectpath>
to the first file I'm having problems with<filename>
- the name of the file I'm having problems with
<projectpath>
- 保存该项目所有组件<hugepath>
的路径 - 从<projectpath>
我遇到问题的第一个文件的路径 -我遇到问题<filename>
的文件的名称
me@work <projectpath>
$ git init
Initialized empty Git repository in <projectpath>/.git/
me@work <projectpath> (master)
$ git add <hugepath>/<filename>
fatal: unable to stat '<hugepath>/<filename>': No such file or directory
me@work <projectpath> (master)
$ ls -al <hugepath>
ls: <hugepath>/<filename>: File or path name too long
total 3
drwxr-xr-x 3 me Administ 0 May 3 2010 .
drwxr-xr-x 4 me Administ 4096 May 3 2010 ..
drwxr-xr-x 2 me Administ 0 May 3 2010 CVS
The msys tools work with paths using the UNC prefix which usually lets you work with long files on windows, but this doesn't seem to get around the path limitation:
msys 工具使用 UNC 前缀处理路径,这通常允许您在 Windows 上处理长文件,但这似乎并没有绕过路径限制:
me@work <projectpath> (master)
$ git add //?/<projectpath>/<hugepath>/<filepath>
fatal: Too long path: //?/<projectpath>/<hugep (intin - the path displayed is trimmed)
me@work <projectpath> (master)
$ ls-al //?/<projectpath>/<hugepath>/
ls: //?/<projectpath>/<hugepath>/.: No such file or directory
ls: //?/<projectpath>/<hugepath>/<filepath>: No such file or directory
total 2
drwxr-xr-x 4 me Administ 4096 May 3 2010 ..
drwxr-xr-x 0 me Administ 0 May 3 2010 CVS
Are there any workarounds you know of for tracking files with long paths using git on Windows?
您知道在 Windows 上使用 git 跟踪长路径文件的任何变通方法吗?
I'm using 1.7.4.msysgit.0 on Windows Vista Business, SP1.
我在 Windows Vista Business SP1 上使用 1.7.4.msysgit.0。
回答by Roy Paterson
The limit is 259 characters, so you're not far off. If the length of <hugepath>/<filename>
is less than 256 characters then you can use the "subst" trick:
限制为 259 个字符,所以您离得不远了。如果 的长度<hugepath>/<filename>
小于 256 个字符,那么您可以使用“subst”技巧:
One option is to use subst
from a Windows command shell:
一种选择是subst
从 Windows 命令外壳使用:
subst P: <projectpath>
Then with mysysgit:
然后使用 mysysgit:
cd /p
<git commands>
Or if that does not work, from a Windows Vista/7/2008 command shell (RunAs administrator) you can create a hard link:
或者,如果这不起作用,您可以从 Windows Vista/7/2008 命令外壳(以管理员身份运行)创建硬链接:
mklink /D C:\p <projectpath>
Then with mysysgit:
然后使用 mysysgit:
C:
cd \p
<git commands>
回答by ak2
Cygwin, and hence its git package, does support such long paths transparently, by automatically mapping them to UNC paths.
Cygwin 及其 git 包通过自动将它们映射到 UNC 路径,确实透明地支持这样的长路径。
回答by Himanshu Dhamija
GIT 1.9 and above version provides you the option for setting longPaths property.
GIT 1.9 及以上版本提供了设置 longPaths 属性的选项。
git config --system core.longpaths true
This property will configure GIT to allow long paths you're trying to checkout.
此属性将配置 GIT 以允许您尝试签出的长路径。
回答by Teocali
There is a git options which allow you to handle long path : core.longpaths. It is available since git 1.9.0.
有一个 git 选项可以让你处理长路径:core.longpaths。它从 git 1.9.0 开始可用。
回答by David Heffernan
This is not a limitation of Windows which in fact supports arbitrarily long file names and has done so for as long as I can remember.
这不是 Windows 的限制,它实际上支持任意长的文件名,并且在我记得的时候就已经这样做了。
I see that you are using //?/
. According to the documentationyou should use \\?\
. When using \\?\
the forward slash is notconverted to a backwards slash.
我看到您正在使用//?/
. 根据您应该使用的文档\\?\
。使用\\?\
正斜杠时不会转换为反斜杠。