Dario
Dario

Reputation: 995

Why am I getting "Commit failed with error: pathspec ... did not match any file(s)"?

I am having some issues with Git.

I have a repository where I can commit any file to without problem. However, there is a single file 'Funder.php' which, when I try committing, tells me there is an error as:

Commit failed with error:
pathspec 'application/libraries/Funder.php' did not match any file(s) known to git.

I am quite new to this, so was wondering if anybody could please help?

Upvotes: 68

Views: 97197

Answers (20)

Nasreen Ustad
Nasreen Ustad

Reputation: 1712

Try using double quotes for "Initial project version"

try using double quotes, if you are work on Windows OS

Upvotes: 0

Roo
Roo

Reputation: 141

My issue was a temporary word backup file starting with ~$, the filename was ~$?????.docx.

I am not sure what was going on - my word document is picked up by GIT using Pycharm so I guess I was editing at somepoint when working with GIT.

I had to create a temporary file with the same name, commit then delete the file.

Upvotes: 0

montonero
montonero

Reputation: 1761

In my case the troublesome file was marked with --skip-worktree. This could be easily checked with

git ls-files -v . | grep ^S

Upvotes: 0

Anup Ghosh
Anup Ghosh

Reputation: 342

I got the same error. I was passing the commit message as part of command line argument. The commit message I was passing with double quotes.

In git commit I was using double quotes again. This was throwing the same error.

So I removed the double quotes from the commit message while calling git commit. This fixed my issues.

git commit -m "%commit_message%"

The above command was throwing the same error

I have changed it to

git commit -m %commit_message%

This fixed my issue.

Upvotes: 0

Daniel Silva
Daniel Silva

Reputation: 990

The reason why this error happens is pointed in this post: https://stackoverflow.com/a/29485441/2769415

Windows’ file system is mostly case-insensitive, so you cannot rename a file by just changing its capitalization. Instead, you will have to use a temporary name in between.

Solution: Rename the file back to the original one, then rename it to a different name, then back to the one with the correct capitalization. Git will not throw the bug anymore.

Example:

Created FOOBar class.
Renamed it to FooBar and then got the error.
Rename it back to FOOBar.
Rename to FooBarTest.
Rename to FooBar.
Git works now.

Upvotes: 54

Fredrick Anyera M
Fredrick Anyera M

Reputation: 633

if working from terminal ensure that you have a message flag in your command.

git commit "Your Commit Message" //Throws an error: pathspec '3.

git commit -m "Your Commit Message" //No error thrown

Upvotes: 4

PWM
PWM

Reputation: 196

I've experienced this by mistakenly creating the branch in a different repo on BitBucket, so make sure you're in the right repo and that the branch exists there.

Upvotes: 0

xleon
xleon

Reputation: 6375

I had a similar problem committing deleted files with SourceTree in Mac. One of the problematic files had accents (áéíóú...). To solve it I had to use terminal rather than SourceTree

Upvotes: 0

R.S.
R.S.

Reputation: 51

I had the same problem with '.entitlements' file, deleting existing file and adding it again worked for me.

Upvotes: 0

NightShovel
NightShovel

Reputation: 3252

My problem was that I was copy / pasting the entire commit line, and it had special characters, which appeared to be normal characters in the console (ex: smart quotes instead of normal quotes). Once I pasted them into a plain-text editor, I saw them, corrected them, and it worked.

Upvotes: 0

Trilochan
Trilochan

Reputation: 553

i had same problem. just change 'Initial comment single quotes '' to double quotes ""

Upvotes: 3

Robert Wasmann
Robert Wasmann

Reputation: 897

With XCode 7.3 I renamed the file in question to FooBar.foo.tmp and then commited once XCode/git added this new file and set the old one to be deleted. Once I commited then I renamed it back (within XCode). Now it's fine. C'est la vie.

Upvotes: 0

serge-k
serge-k

Reputation: 3512

iOS 9.2.1, Xcode 7.2.1, ARC enabled

Ran into this while changing "contents.json" file for my LaunchImage asset catalog. You may elect to use the terminal commands provided as the answer, but try this simpler way...

Source Control -> Refresh Status

enter image description here

Hope this helps. Cheers!

Upvotes: 2

HowardS
HowardS

Reputation: 75

i had the same issue with the word "certificate" as a package name... when i rename the Package to "certificates" it just work... strange ..

Upvotes: 1

Evgeniy Mishustin
Evgeniy Mishustin

Reputation: 3804

I had the same problem. None of the answers here did not help me to resolve the issue. After being stuck for two days, I drew attention that the whole filename with path are very long. I did refactoring renaming it to something less complicated and rearranging folders to reduce the full filename length and it worked!

Upvotes: 2

alaboudi
alaboudi

Reputation: 3423

I had a similar problem but fixed it. I should have been using "" instead of '' in windows command line

Upvotes: 2

julian soro
julian soro

Reputation: 5238

Here's a concise answer on the quickest way to resolve this issue. Similar to @cmbind55 post but to the point.

Problem: I have added a file that I later renamed.

Solution:

  1. Un-add the old file name

git reset HEAD oldFileName.file

  1. Now, add the new file name

git add newFileName.file

  1. Commit and be happy

Upvotes: 6

cmbind55
cmbind55

Reputation: 153

I had this failing commit scenario due to a renamed directory.

This was the originally created directory with a capitalization mistake:

application/Templates/lists/index.html

Within the IDE, I had agreed to add this file to the existing git repo. In later testing, I discovered I had a case-sensitive path issue with the capitalization of "Templates". Within the IDE, I simply renamed the directory to "templates" (changed to lower-case). I did not record the actual sequence of events around this, but later when my commit failed with the following message, I had a hunch this was this issue. Apparently, the IDE did not fully handle this case of renaming a directory.

The IDE commit error message:

Commit failed with error: pathspec "application/templates/lists/index.html" did not match any file(s) known to git.

After doing some reading, my strategy was to take the file back out and then add it again. I unstaged the suspect file

git reset HEAD lists/Templates/lists/index.html

Note, git status only showed the directory here... Not the file.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    lists/templates/

Then, I added back with the corrected directory name (I only used the path for the add, following the lead from git status).

git add lists/templates/

After this, my commit succeeded. I'm not sure if this was the ideal technique, but it resolved the commit error in my case.

Upvotes: 3

Oscar Salguero
Oscar Salguero

Reputation: 10375

I had the same problem in Android Studio after renaming some activities. I tried adding (git add) and moving (git mv) the files but never helped and I was getting the same message again and again.

Finally I decided to backup the classes in the package that had the problematic file in a separate folder in my HDD, then I removed the files from the original folder and in the terminal I did:

rm app/src/main/java/com/path/to/package/with/problematic/files/

Then recreated the deleted package via Android Studio and copied and pasted my classes back there. After that I was able to commit without any issues.

Upvotes: 7

jub0bs
jub0bs

Reputation: 66404

This is the error you get when you attempt to run

git commit <file>

but <file> hasn't been staged yet; in other words, Git hasn't been told about it, yet. This is most likely what's happening here. Run

git add application/libraries/Funder.php

then try to commit.

Upvotes: 45

Related Questions