windows git checkout 错误:无法创建文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14811991/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:15:42  来源:igfitidea点击:

git checkout error: unable to create file

windowsgitfilepathgit-checkout

提问by rohit

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
Cloning into 'git_WA'...
gituser@serveraddr's password:
remote: Counting objects: 500846, done.
remote: Compressing objects: 100% (118676/118676), done.
remote: Total 500846 (delta 307739), reused 483023 (delta 291136)
Receiving objects: 100% (500846/500846), 907.54 MiB | 9.04 MiB/s, done.
Resolving deltas: 100% (307739/307739), done.

error: unable to create file RealR**************************************************************************************************************************************************************************************************************validation.xml (No such file or directory)
Checking out files: 100% (441329/441329)
Checking out files: 100% (441329/441329), done.
done.

$ git clone gituser@serveraddr:/git/git_repo.git git_WA
克隆到'git_WA'...
gituser@serveraddr 的密码:
远程:计数对象:500846,完成。
远程:压缩对象:100% (118676/118676),完成。
远程:总计 500846 (delta 307739),重用 483023 (delta 291136)
接收对象:100% (500846/500846),907.54 MiB | 9.04 MiB/s,完成。
解析增量:100% (307739/307739),完成。

错误:无法创建文件 RealR*********************************************** ****************************************************** ****************************************************** ****************************************************** *************validation.xml(没有这样的文件或目录)

出文件:100% (441329/441329) 签出文件:100% (441329/441329),完成。
完毕。

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:\中的repo,checkout成功,没有错误。

-> It looks like problem with filename/filepath length limitation.

-> 看起来像文件名/文件路径长度限制的问题。

Case-4: checkout the same files from SVN repo. Able to checkout at any location without any problem. Hence no problem from windows side. (Yes, l have data in SVN and GIT both, I just migrated from SVN to GIT).

案例 4:从 SVN 存储库中检出相同的文件。能够在任何地点结账,没有任何问题。因此,从窗户方面看没有问题。(是的,我在 SVN 和 GIT 中都有数据,我刚从 SVN 迁移到 GIT)。

Hence, the problem has to be within msysgit, some filepath length limitation. Can path length in gitclient/msysgit be tweaked?

因此,问题必须在 msysgit 内,某些文件路径长度限制。可以调整 gitclient/msysgit 中的路径长度吗?

Edit1: All operation tried with TortoiseGIT client v1.8.0and git-bash: git version 1.8.0.msysgit.0.
Edit2: Added the actual command used while cloning.

Edit1:所有操作都尝试使用TortoiseGIT 客户端 v1.8.0git-bash: git version 1.8.0.msysgit.0
Edit2:添加了克隆时使用的实际命令。

回答by StevenHB

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 限制之下。

回答by Syed Waqas

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

这将允许它签出文件,即使文件路径较长。问题在于当您尝试删除它时,因为 Windows 不允许删除超过其允许阈值的路径。解决方法是重命名本地存储库中的文件夹,以便减少路径的总长度。例如,路径为 alpha/beta/gamma/universe.txt,可以限制为 1/2/3/universe.txt,使其长度低于 windows 文件大小阈值。

回答by Alexei Osipov

Many Windows APIs are limited to 260 symbols for file path name. So git can't create files with names longer than 260 symbols. NTFS file system actually supports longer names (32k) but there is no easy way to allow long names for programs.

许多 Windows API 的文件路径名限制为 260 个符号。所以 git 不能创建名称超过 260 个符号的文件。NTFS 文件系统实际上支持更长的名称 (32k),但没有简单的方法允许程序使用长名称。

Workaround 1: move your project to a new location, closer to disk root. Advantage:

解决方法 1:将您的项目移动到一个新位置,更靠近磁盘根目录。优势:

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

Disadvantage:

坏处:

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

Workaround 2: create a Junctionto your project folder from a folder that is closer to disk root and do git clone from the junction folder. You can do this with mklinkcommand or Link Shell Extension.

解决方法2:创建一个从接近到磁盘根目录,并从结夹做混帐克隆文件夹到您的项目文件夹中。您可以使用mklinkcommand 或Link Shell Extension执行此操作。

Advantage:

优势:

  • You can have long file names (greater than 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)
  • 您可以保留项目位置
  • 您可以在初始克隆后安全地删除结点(如果您不需要处理在原始位置违反 260 个符号限制的文件)

Disadvantage:

坏处:

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

回答by VonC

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 sessionof 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.
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...).
Only enable this if you know what you're doing and are prepared to live with a few quirks.

为 Windows 版 Git 中的内置命令启用长路径 (> 260) 支持。
默认情况下这是禁用的,因为 Windows 资源管理器、cmd.exe 和 Git for Windows 工具链(msys、bash、tcl、perl...)不支持长路径。
仅当您知道自己在做什么并准备好忍受一些怪癖时才启用此功能。

回答by Jamie Czerwinski

Use Windows PowerShell. Worked for me.

使用 Windows PowerShell。对我来说有效。