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?
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.
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.
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.
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:
- 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:
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.
i had same problem. just change 'Initial comment single quotes '' to double quotes ""
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!
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
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.
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.
In my case the troublesome file was marked with --skip-worktree
. This could be easily checked with
git ls-files -v . | grep ^S
来源:https://stackoverflow.com/questions/28189880/why-am-i-getting-commit-failed-with-error-pathspec-did-not-match-any-file