可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答1:
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.
回答2:
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.
回答3:
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.
回答4:
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
回答5:
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.
回答6:
i had same problem. just change 'Initial comment single quotes '' to double quotes ""
回答7:
I had a similar problem but fixed it. I should have been using "" instead of '' in windows command line
回答8:
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!
回答9:
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!
回答10:
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
回答11:
i had the same issue with the word "certificate" as a package name... when i rename the Package to "certificates" it just work... strange ..
回答12:
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.
回答13:
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.
回答14:
I had the same problem with '.entitlements' file, deleting existing file and adding it again worked for me.
回答15:
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
回答16:
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.