75

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?

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Abdalrahman Shatou
  • 4,550
  • 6
  • 50
  • 79
  • You don't need to take any special steps with git to deal with a Core Data models. They're not even binary, so they can be committed, tracked, and diffed like any source file. Does that file actually exist? Has it been added to the repo before? – Tom Harrington Dec 05 '14 at 23:19
  • The file exists and it has this "M" indicator beside it (modified). – Abdalrahman Shatou Dec 05 '14 at 23:55
  • I have the same problem (though not restricted to the xcdatamodel file). This was the top hit, not very helpful. I hope I can find an answer elsewhere. – Matthew James Briggs Dec 11 '14 at 21:07
  • @MatthewBriggs did you manage to find one? – Abdalrahman Shatou Dec 20 '14 at 18:14
  • @AbdalrahmanShatou unfortunately I can't remember how I resolved this and I don't think I found a specific Q/A regarding this issue. My best guess at this point is that I probably resolved this by committing from the command line. My situation is a little different as I am using github and I think I actually did a push/pull roundtrip with github to resolve the issue. – Matthew James Briggs Dec 21 '14 at 17:12
  • Does this answer your question? [How do I commit case-sensitive only filename changes in Git?](https://stackoverflow.com/questions/17683458/how-do-i-commit-case-sensitive-only-filename-changes-in-git) – TylerH Dec 28 '20 at 21:10

15 Answers15

146

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 
TylerH
  • 20,799
  • 66
  • 75
  • 101
Stan Smulders
  • 6,079
  • 1
  • 27
  • 23
  • 2
    Git choking on file name case is one way to get this error message, but in my case Xcode had two extra files in its commit list and committing from the command line fixed it. I don't think you're correct when you say what "the problem is" for all people with this error. – Ed Norris Oct 26 '15 at 05:00
  • Thanks this saved me a bunch of head scratching! – Chris Jul 27 '23 at 19:02
24

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.

Oleg991
  • 311
  • 2
  • 7
  • The accepted answer worked - ONCE - for me. Any modifications after that? Nope. This one seems the best. I agree, not a cool solution. Maybe next week (WWDC 2020) will solve this better. –  Jun 14 '20 at 17:26
  • Worked so well! Thanks! – jamryu Feb 12 '21 at 05:16
13

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.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Anand Yadav
  • 479
  • 5
  • 17
10

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.

tf.alves
  • 919
  • 8
  • 15
10

Git doesn't like renames where the source and destination differ only by case. (Windows-specific) See How do I commit case-sensitive only filename changes in Git? for solutions.

TylerH
  • 20,799
  • 66
  • 75
  • 101
user3757614
  • 1,776
  • 12
  • 10
9

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.

Bruce Calvert
  • 245
  • 4
  • 10
9

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.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Ahsas
  • 454
  • 5
  • 6
8

I got this error in Xcode, just restarted Xcode and then commited again.

Skyborg
  • 854
  • 13
  • 13
5

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.
xhinoda
  • 1,032
  • 1
  • 19
  • 26
4

I removed .xcdatamodel file, committed, added it and committed again. Not clean, but worked.

Vladimir Shutyuk
  • 2,956
  • 1
  • 24
  • 26
1

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

Hamid Reza Ansari
  • 1,107
  • 13
  • 16
0

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.

Stewart Macdonald
  • 2,062
  • 24
  • 27
0

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.

Sigex
  • 2,834
  • 2
  • 24
  • 25
0

I did everything people suggest but it didn't work for me. I tried to restart my MacBook and it worked.

batuhankrbb
  • 598
  • 7
  • 10
  • 1
    Maybe it worked after a reboot *because* you have applied the other solutions before rebooting... – Eric Aya Dec 28 '20 at 15:47
  • No kiddings, I restart XCode and it works. I didn't try the command line option but everything else with XCode does not work! – user2485972 Jan 14 '22 at 09:33
-1

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

Ahmad Labeeb
  • 1,056
  • 11
  • 21