Git没有这样的文件或目录

时间:2016-10-21 14:09:07

标签: git

我正在构建一个应用程序,并且一如既往地使用Git进行版本控制。

以下是输入和输出,希望你能帮助我:

# git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        app/CodeBehind/Con.php

# git add app/CodeBehind/Con.php
fatal: unable to stat 'app/CodeBehind/Con.php': No such file or directory

对我来说没有任何意义,我还没有找到解决方案,我在两篇文章中读到我应该从Git中删除文件,类似于git rm "[fileName]",但它没有&找到与文件名Con.php匹配的内容。

我该如何解决这个问题?

3 个答案:

答案 0 :(得分:1)

确定发生在我身上,事实证明新的Windows“受控文件夹”保护功能阻止了git。将git添加到允许的应用列表中可以解决此问题。

答案 1 :(得分:0)

路径名太久问题

鉴于OP已经尝试删除并重新添加文件但未成功,问题的关键可能是Con.php的完整路径已达到260字符限制在窗户。但是,当我尝试重现此问题时,错误消息明确表示fatal: unable to stat 'very/long/path/name': Filename too long所以我不确定这是否是问题。

要检查这是否是问题,切换到包含Con.php 的目录并执行以下操作:

pwd -W | wc -c

这应该计算当前目录的Windows路径中的字符数。如果计数&gt; = 260,那么这不是问题,我建议您转到下面的Debugging other issues部分。但是,如果计数>&gt; = 260,则按以下步骤操作:

git config --system core.longpaths true

然后再次尝试添加文件。

请参阅下面的操作,创建一个包含&gt; 260个字符的路径,并设置上述选项以证明它可以解决问题。

$ git add 12345
fatal: unable to stat 'This/Is/A/Very/long/pathname/with/more/than/two/hundred/and/sixty/characters/This/Is/A/Very/long/pathname/with/more/than/two/hundred/and/sixty/characters/This/Is/A/Very/long/pathname/with/more/than/two/hundred/more/dir/12345': Filename too long

$ git config --system core.longpaths true
$ git add 12345  #Notice that there is no error now
$ git status     #Shows that the file was successfully staged

On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   12345

为什么此配置不是默认配置?
如果您对此感到疑惑,请阅读 this

  

Windows不能正确支持超过的文件和目录   260个字符。这适用于Windows资源管理器,cmd.exe和许多   其他应用程序(包括许多IDE以及bash,perl和tcl   随Git for Windows一起发布。)

并注意这一点:

  

使用此选项,脚本git命令可能仍会失败,因此请使用此选项   自己的风险

调试其他问题

如果过长的路径名不是问题,那么尝试执行以下命令(当然将git add 12345更改为git add app/CodeBehind/Con.php)并查看输出线索(并将其添加到你的问题,以帮助其他读者找出问题):

$ set -x; GIT_TRACE=2 GIT_CURL_VERBOSE=2 GIT_TRACE_PERFORMANCE=2 GIT_TRACE_PACK_ACCESS=2 GIT_TRACE_PACKET=2 GIT_TRACE_PACKFILE=2 GIT_TRACE_SETUP=2 GIT_TRACE_SHALLOW=2 git add 12345; set +x;

+ GIT_TRACE=2
+ GIT_CURL_VERBOSE=2
+ GIT_TRACE_PERFORMANCE=2
+ GIT_TRACE_PACK_ACCESS=2
+ GIT_TRACE_PACKET=2
+ GIT_TRACE_PACKFILE=2
+ GIT_TRACE_SETUP=2
+ GIT_TRACE_SHALLOW=2
+ git add 12345
16:06:04.269773 trace.c:333             setup: git_dir: .git
16:06:04.269773 trace.c:334             setup: git_common_dir: .git
16:06:04.269773 trace.c:335             setup: worktree: C:/Users/az/test-long-path-problems
16:06:04.269773 trace.c:336             setup: cwd: C:/Users/az/test-long-path-problems
16:06:04.269773 trace.c:337             setup: prefix: This/Is/A/Very/long/pathname/with/more/than/two/hundred/and/sixty/characters/This/Is/A/Very/long/pathname/with/more/than/two/hundred/and/sixty/characters/This/Is/A/Very/long/pathname/with/more/than/two/hundred/more/dir/
16:06:04.269773 git.c:350               trace: built-in: git 'add' '12345'
16:06:04.269773 trace.c:435             performance: 0.006209300 s: git command: 'git.exe' 'add' '12345'
+ set +x

答案 2 :(得分:-1)

我遇到了同样的问题.. 转到病毒和威胁防护设置,然后关闭下面的受控文件夹访问选项。 然后再试一次。它会运行。

相关问题