【问题标题】:How to fix "Filename too long error" during git clone如何在 git clone 期间修复“文件名太长错误”
【发布时间】:2019-03-12 22:36:51
【问题描述】:

我正在尝试使用以下命令从我的 bitbucket 存储库的特定分支中获取 git clone: git clone <url> --branch <branchname>.

但是,我在进行克隆时遇到以下错误:

error:unable to create file foldername/nodemodules/......: 文件名 太长了。

我尝试通过在我的 git cmd 中运行以下命令来解决此问题 git config --system core.longpaths true.

但我得到了:

错误:无法锁定配置文件 c://.gitconfig:权限被拒绝 错误:无法锁定配置文件 c://.gitconfig:参数无效。

如何解决这两个错误?

【问题讨论】:

标签: java windows git github gitlab


【解决方案1】:
  1. 以管理员身份启动 Git Bash
  2. 运行命令git config --system core.longpaths true

另一种方式(仅适用于此克隆):

git clone -c core.longpaths=true <repo-url>

【讨论】:

  • 嘿,谢谢!!这对我有用。 git clone -c core.longpaths=true
  • 如果您使用的是 UI 工具并且上述方法没有帮助.. .. >> 解决方案 >> 如上所述将“longpaths=true”添加到核心部分>> C:\Users [---YOU-- ]\AppData\Local\Fork\gitInstance\2.20.1\mingw64\etc\gitconfig(适用于 Windows 10 上的 Fork)
  • 如果我们没有对计算机的管理员访问权限,我们似乎无法执行此操作。
【解决方案2】:

您可以尝试使用命令设置长路径: git config --system core.longpaths true

【讨论】:

  • 您必须以管理员权限执行
  • 如果您只需要对单个存储库进行更改,您可以在没有 --system 的情况下运行并且不需要管理员权限:git config core.longpaths true
【解决方案3】:

而不是 git config --system core.longpaths true 试试看,

git config --global core.longpaths true , 

--system 将为系统上的所有用户设置变量,但您正在寻找的是为当前登录用户设置它。

【讨论】:

    【解决方案4】:

    在 Windows 上,文件名的最大长度限制为 260 个字符。

    请参阅https://superuser.com/questions/811146/windows-7-file-name-length-limited-to-129-characters 了解如何删除它。

    【讨论】:

      【解决方案5】:

      我没有管理员权限。所以我不得不去 .git 文件夹(隐藏)中的配置文件,该文件夹与您在本地机器中启动克隆的文件夹相同。 然后在 [core] 下添加“longpaths = true”。从 Git Bash 运行 git reset --hard origin/xxx。这对我有用。

      【讨论】:

        【解决方案6】:

        基本上,我们需要在我们的本地 git 配置文件中的 core 部分下将变量“longpaths”设置为 true。

        您可以在路径导航到它

        <git-repo>\.git\config
        

        或者,您可以通过以下命令使用 git bash 克隆您的代码

        git clone -c core.longpaths=true <repo-url>
        

        【讨论】:

          【解决方案7】:

          如果命令git config core.longpaths true 不起作用,请尝试手动更改。

          转到项目的.git 文件夹(确保您在文件资源管理器中启用了隐藏项目视图)并打开config 文件。文件内容如下所示

          [core]
              repositoryformatversion = 0
              filemode = false
              bare = false
              logallrefupdates = true
              symlinks = false
              ignorecase = true
              hideDotFiles = dotGitOnly
          [remote "origin"]
              url = https://<domain>/scm/<project>/<repo>.git
              fetch = +refs/heads/*:refs/remotes/origin/*
          [branch "master"]
              remote = origin
              merge = refs/heads/master
          

          [core] 部分下手动添加longpaths = true 属性。保存它并尝试从新的 git bash 会话中提取代码。它会解决这个问题。

          [core]
                  repositoryformatversion = 0
                  filemode = false
                  bare = false
                  logallrefupdates = true
                  symlinks = false
                  ignorecase = true
                  hideDotFiles = dotGitOnly
                  longpaths = true
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2022-06-14
            • 2019-11-14
            • 2017-12-26
            • 1970-01-01
            • 2022-12-13
            • 2014-03-11
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多