Xcode - error: pathspec '...' did not match any file(s) known to git
XcodeGitCore DataXcode Problem Overview
I am using a local git repo. When I try to commit changes to the core data model file (.xcdatamodel), I get this message:
error: pathspec '.../DataModel.xcdatamodeld/DataModel.xcdatamodel/contents' did not match any file(s) known to git.
How to fix this and commit the model as I do with any other file?
Xcode Solutions
Solution 1 - Xcode
The problem is, indeed, the changing of a filename's case. For me this was because of my Macbook/OSX. Apparently Windows has the same 'thing'.
Cause: git isn't able to recognise a change from 'filename' to 'FileName'.
Here's a list of solutions for anyone stumbling upon this. All the solutions should be run at the project root:
The Permanent fix that will work on current and future projects
Change the git case setting. The file should be committed afterwards
git config core.ignorecase false --global
The Project only fix
git config core.ignorecase false
The just give me a line of code so I can move on fix - credit to Bruce
git commit -a -m "pathspec did not match any file(s) known to git fix"
The I get paid by the hour fix
Delete the file. Commit. Push. Add the file again. Commit. Push.
Based on your needs you may want to revert the settings. Do:
git config core.ignorecase true
Solution 2 - Xcode
I solved the problem simply by closing XCODE and opening it again. I know it is not a cool solution, but it worked without any changes to any files on my part.
Solution 3 - Xcode
I got the same error using xcode 9.1. I solved it by manual commit from the terminal. The steps are as follows
- move to your project folder/directory
- $ git status - you will get to know the changes done to your project
- $ git add .
- $ git commit -m"your message"
- $ git push origin master
Once you manually commit all the changes successfully from the terminal, then you can use source control in xcode.
Solution 4 - Xcode
This is not a proper way to solve the problem, but it's a workaround that may help others... Do this in your terminal:
git commit -m "<message>" <project dir>
Replace
Solution 5 - Xcode
Git doesn't like renames where the source and destination differ only by case. (Windows-specific) See https://stackoverflow.com/questions/17683458/how-do-i-commit-case-sensitive-only-filename-changes-in-git for solutions.
Solution 6 - Xcode
This is similar to tf.alves answer, but normally I do a
git commit -a -m "comment"
I've found that if I forget the -a and -m parameters that I get the error: pathspec message mentioned above.
Solution 7 - Xcode
I got this error in Xcode, just restarted Xcode and then commited again.
Solution 8 - Xcode
I faced the same issue after renaming a storyboard file. The following steps fixed it for me -
- Clean (Shift + Command + K)
- Build (Command + B)
- Commit
Not sure but I think it could be that git was holding reference to the old file name and cleaning the build folder and building again corrected that.
Solution 9 - Xcode
I fix like this:
- Go to your project directory with the terminal (console)
- Execute the command: git status //this show you the Untracked files
- Add all Untracked files with this command: git add -A
- You can commit with xcode source control, and then push.
Solution 10 - Xcode
I removed .xcdatamodel file, committed, added it and committed again. Not clean, but worked.
Solution 11 - Xcode
I got this error in Xcode after I'd changed the file extension on one of my files (changed .txt to .json). I solved it by right-clicking on the file, selecting Source Control -> Commit Selected Files...
, and committing just that file. After that, I was able to go back to Source Control -> Commit
(from the menubar), and the rest of the files were committed successfully.
Solution 12 - Xcode
This fixed it for me. Remove the file from your project. I dragged it to a different folder. I then removed the reference, cleaned the project and then built the project.
Then commit and push to your git. Then add the file back and then commit again.
Solution 13 - Xcode
I fixed this problem by removing the local project repository and recreate it.
Delete your local (Xcode) and online (Github) repository and create a new repository and commit the project to it again.
To delete the git repository from your project:
-
Open a terminal and paste this command for enabling show hidden file in finder
defaults write com.apple.finder AppleShowAllFiles TRUE killall Finder
-
Open the project folder and delete the
.git
folder -
Restart Xcode
-
Now create a new git repository and commit the project
Solution 14 - Xcode
I did everything people suggest but it didn't work for me. I tried to restart my MacBook and it worked.
Solution 15 - Xcode
my duplicate solution is to restart Xcode I was rename a file before from "name" to "Name" after restarting, it committed as "name" but file name still "Name" on disk but "name" on git