Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git no such file or directory

Tags:

git

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

To me that doesn't make any sense and I haven't found a solution yet, I read in two post that I should remove the file from Git, something like git rm "[fileName]" but it doesn't find a match with the file name Con.php.

How can I fix this?

like image 731
Daniel Novoa Avatar asked Oct 21 '16 14:10

Daniel Novoa


People also ask

How do I change directory in git bash?

To change this current working directory, you can use the "cd" command (where "cd" stands for "change directory"). For example, to move one directory upwards (into the current folder's parent folder), you can just call: $ cd ..

What happens when you git clone?

Git clone is used to copy an existing Git repository into a new local directory. The Git clone command will create a new local directory for the repository, copy all the contents of the specified repository, create the remote tracked branches, and checkout an initial branch locally.

What is the push command in git?

The git push command is used to upload local repository content to a remote repository. Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch , but whereas fetching imports commits to local branches, pushing exports commits to remote branches.


2 Answers

OK that happened to me and it turns out that the new windows "controlled folder" protection feature is blocking git. adding git to the allowed apps list solved the problem.

like image 106
EKanadily Avatar answered Sep 27 '22 19:09

EKanadily


Pathname too long problem

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


Debugging other issues

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
like image 29
Ashutosh Jindal Avatar answered Sep 27 '22 18:09

Ashutosh Jindal