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

GitGit Commit

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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.

Solution 3 - Git

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.

Solution 4 - Git

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

Solution 5 - Git

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

Solution 6 - Git

I had this failing commit scenario due to a renamed directory.

This was the originally created directory with a capitalization mistake:

application/Templates/lists/index.html

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.

Solution 7 - Git

i had same problem. just change 'Initial comment single quotes '' to double quotes ""

Solution 8 - Git

I had a similar problem but fixed it. I should have been using "" instead of '' in windows command line

Solution 9 - Git

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!

Solution 10 - Git

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

enter image description here

Hope this helps. Cheers!

Solution 11 - Git

i had the same issue with the word "certificate" as a package name... when i rename the Package to "certificates" it just work... strange ..

Solution 12 - Git

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.

Solution 13 - Git

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.

Solution 14 - Git

I had the same problem with '.entitlements' file, deleting existing file and adding it again worked for me.

Solution 15 - Git

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

Solution 16 - Git

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.

Solution 17 - Git

I got the same error. I was passing the commit message as part of command line argument. The commit message I was passing with double quotes.

In git commit I was using double quotes again. This was throwing the same error.

So I removed the double quotes from the commit message while calling git commit. This fixed my issues.

git commit -m "%commit_message%"

The above command was throwing the same error

I have changed it to

git commit -m %commit_message%

This fixed my issue.

Solution 18 - Git

In my case the troublesome file was marked with --skip-worktree. This could be easily checked with

git ls-files -v . | grep ^S

Solution 19 - Git

My issue was a temporary word backup file starting with ~$, the filename was ~$?????.docx.

I am not sure what was going on - my word document is picked up by GIT using Pycharm so I guess I was editing at somepoint when working with GIT.

I had to create a temporary file with the same name, commit then delete the file.

Solution 20 - Git

Try using double quotes for "Initial project version"

try using double quotes, if you are work on Windows OS

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDarioView Question on Stackoverflow
Solution 1 - GitDaniel SilvaView Answer on Stackoverflow
Solution 2 - Gitjub0bsView Answer on Stackoverflow
Solution 3 - GitOscar SalgueroView Answer on Stackoverflow
Solution 4 - GitJulian SoroView Answer on Stackoverflow
Solution 5 - GitFredrick Anyera MView Answer on Stackoverflow
Solution 6 - Gitcmbind55View Answer on Stackoverflow
Solution 7 - GitTrilochanView Answer on Stackoverflow
Solution 8 - GitalaboudiView Answer on Stackoverflow
Solution 9 - GitEvgeniy MishustinView Answer on Stackoverflow
Solution 10 - Gitserge-kView Answer on Stackoverflow
Solution 11 - GitHowardSView Answer on Stackoverflow
Solution 12 - GitRobert WasmannView Answer on Stackoverflow
Solution 13 - GitNightShovelView Answer on Stackoverflow
Solution 14 - GitR.S.View Answer on Stackoverflow
Solution 15 - GitxleonView Answer on Stackoverflow
Solution 16 - GitPWMView Answer on Stackoverflow
Solution 17 - GitAnup GhoshView Answer on Stackoverflow
Solution 18 - GitmontoneroView Answer on Stackoverflow
Solution 19 - GitRooView Answer on Stackoverflow
Solution 20 - GitNasreen UstadView Answer on Stackoverflow