Jim Jim - 3 months ago 18x
Swift Question

How can I fix error: pathspec 'git-practice-project/git-practice-project' did not match any file(s) known to git

I've created a project to practice using Git with Xcode and GitHub. After a lot of work, I've got the repositories created both locally and remotely. I just tried to make a commit and got this error:

enter image description here

Here's what I'm trying to commit:

enter image description here

The last things I did before I got this error were:

  • I added a .gitignore file using the GitHub Swift template in order to remove the .xcscheme file from the cache

  • from the Terminal, I ran 'git rm --cache'

  • I created the test_file and then tried to Commit

But I can see the folder in the finder:

enter image description here

I looked around SO a lot and found many questions about git commit problem but what I found had mostly to do with diacritics and other issues that aren't the same as mine.

Did the 'git rm --cache' lead to this situation? What can/should I do to safely correct this problem?


Update: Seems I really got myself into pickle. I've got nested 'git-practice-project' directories several levels deep:

enter image description here

I've started at the deepest directory, did an ls, and a git status, the backed myself up to the top doing the same thing at each level. It looks like only the two highest directories have uncommitted changes and the project.pbxproj file exists in both of them.


I don't use Xcode's SCM features so I am not sure why Xcode is confused here. But it looks like the files under git-practice-project/git-practice-project aren't known to git yet. You need to add the directory to git. On the command line from the project's root directory you could try:

git status

That should list your files that have been modified, deleted, and that aren't part of the git repo yet.

Add the directory and its contents:

git add git-practice-project

Once you have done that, you should be good to go to use the SCM tools in Xcode again.

Update: In Xcode, you can select the file that is marked with the ? and then go to the Source Control menu and select Add Selected Files.