简体   繁体   English

git checkout错误:无法创建文件

[英]git checkout error: unable to create file

While cloning a git repository from Linux to a Windows system, I am getting the following error in checkout the phase: 在将git存储库从Linux克隆到Windows系统时,我在结帐阶段遇到以下错误:

$ git clone gituser@serveraddr:/git/git_repo.git git_WA $ git clone gituser @ serveraddr:/git/git_repo.git git_WA
Cloning into 'git_WA'... 克隆到'git_WA'......
gituser@serveraddr's password: gituser @ serveraddr的密码:
remote: Counting objects: 500846, done. remote:计数对象:500846,完成。
remote: Compressing objects: 100% (118676/118676), done. remote:压缩对象:100%(118676/118676),完成。
remote: Total 500846 (delta 307739), reused 483023 (delta 291136) 远程:总计500846(delta 307739),重用483023(delta 291136)
Receiving objects: 100% (500846/500846), 907.54 MiB | 接收物体:100%(500846/500846),907.54 MiB | 9.04 MiB/s, done. 完成9.04 MiB / s。
Resolving deltas: 100% (307739/307739), done. 解决增量:100%(307739/307739),完成。

error: unable to create file RealR**************************************************************************************************************************************************************************************************************validation.xml (No such file or directory) 错误:无法创建文件RealR ******************************************* ************************************************** ************************************************** ************************************************** ************* validation.xml(没有这样的文件或目录)
Checking out files: 100% (441329/441329) 签出文件:100%(441329/441329)
Checking out files: 100% (441329/441329), done. 签出文件:100%(441329/441329),完成。
done. 完成。

Case-2: Cloned as bare repo, checked-out all from bare repo locally => Same error. 案例2:克隆为裸仓库,从本地裸仓库中检出全部=>相同的错误。

Case-3: Clone the repo in C:\\ directly, checkout successful, No error. 案例3:直接克隆C:\\中的仓库,结账成功,无错误。

-> It looks like problem with filename/filepath length limitation. - >看起来像文件名/文件路径长度限制的问题。

Case-4: checkout the same files from SVN repo. 案例4:从SVN repo签出相同的文件。 Able to checkout at any location without any problem. 能够在任何位置结账,没有任何问题。 Hence no problem from windows side. 因此从Windows端没有问题。 (Yes, l have data in SVN and GIT both, I just migrated from SVN to GIT). (是的,我在SVN和GIT中都有数据,我只是从SVN迁移到GIT)。

Hence, the problem has to be within msysgit, some filepath length limitation. 因此,问题必须在msysgit内,一些文件路径长度限制。 Can path length in gitclient/msysgit be tweaked? 可以调整gitclient / msysgit中的路径长度吗?

Edit1: All operation tried with TortoiseGIT client v1.8.0 and git-bash: git version 1.8.0.msysgit.0 . Edit1: 所有操作都尝试使用TortoiseGIT客户端v1.8.0git-bash:git版本1.8.0.msysgit.0
Edit2: Added the actual command used while cloning. Edit2:添加了克隆时使用的实际命令。

I experienced similar problems when checking out a project into a Windows directory that had a 67- (Windows) or 76- (cygwin) character base path - when added to the path-length of the checked out files, it exceeded Windows' path-length limit: 将项目签出到具有67-(Windows)或76-(cygwin)字符库路径的Windows目录时,我遇到了类似的问题 - 当添加到签出文件的路径长度时,它超出了Windows的路径 - 长度限制:

git checkout -f HEAD
error: unable to create file <194-character filepath> (No such file or directory)
fatal: cannot create directory at '<187-character directory path>': No such file
or directory

I solved the problem by checking out the git repository to c:\\git , which, at 6 or 15 characters in length, kept the maximum path-length under the Windows limit. 我通过将git存储库签出到c:\\ git解决了这个问题 ,它的长度为6或15个字符,保持Windows限制下的最大路径长度。

Try: 尝试:

git config --system core.longpaths true

This will allow it to checkout the files even with longer filepaths. 这将允许它检查文件,即使文件路径较长。 The issue with this would be when you try to delete it, as Windows will not allow to delete a path longer than it's allowed threshold. 这个问题就是当你试图删除它时,因为Windows不允许删除超过允许阈值的路径。 The workaround to that is to rename the folders in the local repository, so that the overall length of the path is lessened. 解决方法是重命名本地存储库中的文件夹,以减少路径的总长度。 For example, a path that is alpha/beta/gamma/universe.txt, can be limited to 1/2/3/universe.txt, so that it's length is under the windows filesize threshold. 例如,alpha / beta / gamma / universe.txt的路径可以限制为1/2/3 / universe.txt,因此它的长度在windows filesize阈值之下。

Many Windows APIs are limited to 260 symbols for file path name. 许多Windows API限制为260个符号用于文件路径名。 So git can't create files with names longer than 260 symbols. 因此git无法创建名称超过260个符号的文件。 NTFS file system actually supports longer names (32k) but there is no easy way to allow long names for programs. NTFS文件系统实际上支持更长的名称(32k),但没有简单的方法来允许程序的长名称。

Workaround 1: move your project to a new location, closer to disk root. 解决方法1:将项目移动到更靠近磁盘根目录的新位置。 Advantage: 优点:

  • Everything should work fine (assuming there no files with path longer 260) 一切都应该工作正常(假设没有路径更长的文件260)

Disadvantage: 坏处:

  • You have to change project location 您必须更改项目位置

Workaround 2: create a Junction to your project folder from a folder that is closer to disk root and do git clone from the junction folder. 解决方法2:从更靠近磁盘根目录的文件夹创建项目文件夹的Junction ,并从联结文件夹执行git clone。 You can do this with mklink command or Link Shell Extension . 您可以使用mklink命令或Link Shell Extension执行此操作。

Advantage: 优点:

  • You can have long file names (greater than 260) 您可以拥有长文件名(大于260)
  • You can preserver project location 您可以保留项目位置
  • You may safely delete junction after initial cloning (if you don't need to work with files that violate 260 symbol limit at original location) 您可以在初始克隆后安全地删除联结(如果您不需要处理在原始位置违反260符号限制的文件)

Disadvantage: 坏处:

  • Full file name at junction still have to be less 260 symbols. 交叉点的完整文件名仍然必须少于260个符号。 Otherwise this solution will not help. 否则此解决方案将无济于事。
  • If you want to modify the files with long 如果要用long修改文件

The only suggestion I saw, considering a similar issue , was: 考虑到类似的问题 ,我看到的唯一建议是:

Workaround: use http://www.cygwin.com/ 解决方法:使用http://www.cygwin.com/

Or at least check if a checkout in a git-bash session of msysgit works better. 或者至少检查msysgit的git-bash会话中的结账是否更好。


Update May 2015 (2 years later): 2015年5月更新(2年后):

Note: the latest 2.4.1 git-for-windows proposes : 注意: 最新的2.4.1 git-for-windows建议

core.longpaths::

Enable long path (> 260) support for builtin commands in Git for Windows. 在Git for Windows中为内置命令启用长路径(> 260)支持。
This is disabled by default, as long paths are not supported by Windows Explorer, cmd.exe and the Git for Windows tool chain (msys, bash, tcl, perl...). 默认情况下禁用此选项,因为Windows资源管理器,cmd.exe和Git for Windows工具链(msys,bash,tcl,perl ...)不支持长路径。
Only enable this if you know what you're doing and are prepared to live with a few quirks. 只有在你知道自己在做什么并且准备好生活在一些怪癖时才启用它。

Use Windows PowerShell. 使用Windows PowerShell。 Worked for me. 为我工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM