Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting "Commit failed with error: pathspec ... did not match any file(s)"?

Tags:

git

git-commit

I am having some issues with Git.

I have a repository where I can commit any file to without problem. However, there is a single file 'Funder.php' which, when I try committing, tells me there is an error as:

Commit failed with error:
pathspec 'application/libraries/Funder.php' did not match any file(s) known to git.

I am quite new to this, so was wondering if anybody could please help?

like image 737
Dario Avatar asked Jan 28 '15 10:01

Dario


4 Answers

The reason why this error happens is pointed in this post: https://stackoverflow.com/a/29485441/2769415

Windows’ file system is mostly case-insensitive, so you cannot rename a file by just changing its capitalization. Instead, you will have to use a temporary name in between.

Solution: Rename the file back to the original one, then rename it to a different name, then back to the one with the correct capitalization. Git will not throw the bug anymore.

Example:

Created FOOBar class.
Renamed it to FooBar and then got the error.
Rename it back to FOOBar.
Rename to FooBarTest.
Rename to FooBar.
Git works now.
like image 129
Daniel Silva Avatar answered Nov 01 '22 05:11

Daniel Silva


This is the error you get when you attempt to run

git commit <file>

but <file> hasn't been staged yet; in other words, Git hasn't been told about it, yet. This is most likely what's happening here. Run

git add application/libraries/Funder.php

then try to commit.

like image 35
jub0bs Avatar answered Nov 01 '22 04:11

jub0bs


I had the same problem in Android Studio after renaming some activities. I tried adding (git add) and moving (git mv) the files but never helped and I was getting the same message again and again.

Finally I decided to backup the classes in the package that had the problematic file in a separate folder in my HDD, then I removed the files from the original folder and in the terminal I did:

rm app/src/main/java/com/path/to/package/with/problematic/files/

Then recreated the deleted package via Android Studio and copied and pasted my classes back there. After that I was able to commit without any issues.

like image 7
Oscar Salguero Avatar answered Nov 01 '22 04:11

Oscar Salguero


Here's a concise answer on the quickest way to resolve this issue. Similar to @cmbind55 post but to the point.

Problem: I have added a file that I later renamed.

Solution:

  1. Un-add the old file name

git reset HEAD oldFileName.file

  1. Now, add the new file name

git add newFileName.file

  1. Commit and be happy
like image 6
Julian Soro Avatar answered Nov 01 '22 05:11

Julian Soro