I'm building an application and as always I'm using Git for version control.
Below are the inputs and outputs, hope you can help me:
# git status
On branch master
(use "git add <file>..." to include in what will be committed)
# git add app/CodeBehind/Con.php
fatal: unable to stat 'app/CodeBehind/Con.php': No such file or directory
git rm "[fileName]"
Given that the OP has already tried removing and re-adding the file without success, it is possible that the crux of the problem is that the complete path of
Con.php has hit the 260 character limit in windows. However, when I tried to reproduce this problem, the error message clearly said
fatal: unable to stat 'very/long/path/name': Filename too long so am not certain that that is the problem.
To check if this is the problem, switch to the directory containing
Con.php and execute the following:
pwd -W | wc -c
That should give you a count of the number of characters in the windows path of the current directory. If the count is not >=260 then this is not the problem and I would recommend moving on to
Debugging other issues section below. However, if the count is >= 260, then proceed as follows:
git config --system core.longpaths true
and then try adding the file again.
See this in action below, which creates a path with >260 characters and the sets the above option to prove that it fixes the problem.
$ 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
Why is this configuration not the default?
If you were wondering about that, read this:
Windows does not properly support files and directories longer than 260 characters. This applies to Windows Explorer, cmd.exe and many other applications (including many IDEs as well as bash, perl and tcl that come with Git for Windows).
and note this caveat:
Scripted git commands may still fail with this option, so use at your own risk
If too-long-a-pathname is not the problem, then try executing the following command (of course changing
git add 12345 to
git add app/CodeBehind/Con.php) and look at the ouptput for clues (and add this to your question to assist other readers in finding out the issue) :
$ 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