Why am I getting “Commit failed with error: pathspec … did not match any file(s)”?
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?
16 Solutions collect form web for “Why am I getting “Commit failed with error: pathspec … did not match any file(s)”?”
This is the error you get when you attempt to run
git commit <file>
<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.
The reason why this error happens is pointed in this post: https://stackoverflow.com/a/29485441/2769415
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.
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.
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:
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.
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.
- Un-add the old file name
git reset HEAD oldFileName.file
- Now, add the new file name
git add newFileName.file
- Commit and be happy
I had this failing commit scenario due to a renamed directory.
This was the originally created directory with a capitalization mistake:
Within the IDE, I had agreed to add this file to the existing git repo.
In later testing, I discovered I had a case-sensitive path issue with the capitalization of “Templates”. Within the IDE, I simply renamed the directory to “templates” (changed to lower-case). I did not record the actual sequence of events around this, but later when my commit failed with the following message, I had a hunch this was this issue. Apparently, the IDE did not fully handle this case of renaming a directory.
The IDE commit error message:
Commit failed with error: pathspec
“application/templates/lists/index.html” did not match any file(s)
known to git.
After doing some reading, my strategy was to take the file back out and then add it again. I unstaged the suspect file
git reset HEAD lists/Templates/lists/index.html
Note, git status only showed the directory here… Not the file.
Untracked files: (use "git add <file>..." to include in what will be committed) lists/templates/
Then, I added back with the corrected directory name (I only used the path for the add, following the lead from git status).
git add lists/templates/
After this, my commit succeeded. I’m not sure if this was the ideal technique, but it resolved the commit error in my case.
I had a similar problem but fixed it. I should have been using “” instead of ” in windows command line
I had the same problem. None of the answers here did not help me to resolve the issue. After being stuck for two days, I drew attention that the whole filename with path are very long. I did refactoring renaming it to something less complicated and rearranging folders to reduce the full filename length and it worked!
iOS 9.2.1, Xcode 7.2.1, ARC enabled
Ran into this while changing “contents.json” file for my LaunchImage asset catalog. You may elect to use the terminal commands provided as the answer, but try this simpler way…
Source Control -> Refresh Status
Hope this helps. Cheers!
i had same problem. just change ‘Initial comment single quotes ” to double quotes “”
i had the same issue with the word “certificate” as a package name… when i rename the Package to “certificates” it just work… strange ..
With XCode 7.3 I renamed the file in question to FooBar.foo.tmp and then commited once XCode/git added this new file and set the old one to be deleted. Once I commited then I renamed it back (within XCode). Now it’s fine. C’est la vie.
My problem was that I was copy / pasting the entire commit line, and it had special characters, which appeared to be normal characters in the console (ex: smart quotes instead of normal quotes). Once I pasted them into a plain-text editor, I saw them, corrected them, and it worked.
I had the same problem with ‘.entitlements’ file, deleting existing file and adding it again worked for me.
I had a similar problem committing deleted files with SourceTree in Mac.
One of the problematic files had accents (áéíóú…). To solve it I had to use terminal rather than SourceTree
I’ve experienced this by mistakenly creating the branch in a different repo on BitBucket, so make sure you’re in the right repo and that the branch exists there.
if working from terminal ensure that you have a message flag in your command.
git commit "Your Commit Message" //Throws an error: pathspec '3.
git commit -m "Your Commit Message" //No error thrown