Xcode - error: pathspec '...' did not match any file(s) known to git

XcodeGitCore Data

Xcode 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

  1. move to your project folder/directory
  2. $ git status - you will get to know the changes done to your project
  3. $ git add .
  4. $ git commit -m"your message"
  5. $ 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 with your message, and with the directory of your project.

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 -

  1. Clean (Shift + Command + K)
  2. Build (Command + B)
  3. 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:

  1. Go to your project directory with the terminal (console)
  2. Execute the command: git status //this show you the Untracked files
  3. Add all Untracked files with this command: git add -A
  4. 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:

  1. Open a terminal and paste this command for enabling show hidden file in finder

    defaults write com.apple.finder AppleShowAllFiles TRUE
    killall Finder
    
  2. Open the project folder and delete the .git folder

  3. Restart Xcode

  4. 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

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
QuestionAbdalrahman ShatouView Question on Stackoverflow
Solution 1 - XcodeStan SmuldersView Answer on Stackoverflow
Solution 2 - XcodeOleg991View Answer on Stackoverflow
Solution 3 - XcodeAnand YadavView Answer on Stackoverflow
Solution 4 - Xcodetf.alvesView Answer on Stackoverflow
Solution 5 - Xcodeuser3757614View Answer on Stackoverflow
Solution 6 - XcodeBruce CalvertView Answer on Stackoverflow
Solution 7 - XcodeSkyborgView Answer on Stackoverflow
Solution 8 - XcodeAhsasView Answer on Stackoverflow
Solution 9 - XcodexhinodaView Answer on Stackoverflow
Solution 10 - XcodeVladimir ShutyukView Answer on Stackoverflow
Solution 11 - XcodeStewart MacdonaldView Answer on Stackoverflow
Solution 12 - XcodeSigexView Answer on Stackoverflow
Solution 13 - XcodeHamid Reza AnsariView Answer on Stackoverflow
Solution 14 - XcodebatuhankrbbView Answer on Stackoverflow
Solution 15 - XcodeAhmad LabeebView Answer on Stackoverflow