简体   繁体   中英

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

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?

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 

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.

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.

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.

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.

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.

我在 Xcode 中遇到了这个错误,只是重新启动了 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.

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.

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

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.

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.

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

我重复的解决方案是重新启动 Xcode 我在重新启动后将文件从“名称”重命名为“名称”,它提交为“名称”,但文件名在磁盘上仍然是“名称”,但在 git 上是“名称”

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM