git error: unable to create file (Invalid argument)

A file was added to a project's git repository at work with an illegal filename (under Windows). The filename had an invalid character in the extension: a question mark.

When I tried fetching/rebasing with TortoiseGit an error message popped up which contained "error: unable to create file /path/to/file.ext? (Invalid argument)". Confused, I looked at the upstream's log and, effectively, a file with an invalid character in the extension had been added.

To solve the issue I dropped down to git's command line:

$ git fetch
$ git rebase
First, rewinding head to replay your work on top of it...
error: unable to create file Path/file.ext? (Invalid argument)
Applying: My local commit. 

The problematic file wasn't created in my working directory, but the rebase worked correctly. All that was needed was to delete the file with the invalid character in the extension from git's index (as it wasn't in my working directory), commit and push so we could continue working.

$ git rm --cached Path/file.ext?
rm 'Path/file.ext?'
$ git commit -m "Delete problematic file with invalid character."
[develop bdf3b40] Delete problematic file with invalid character.
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 Path/file.ext? 

Then I pushed and all was right again. The important part was to remove the file from git's index, leaving the working tree alone. Attempting to just git rm the file would result in

$git rm Path/file.ext?
fatal: pathspec 'Path/file.ext?' did not match any files 

I was able to do this so quickly thanks to an article on git reset I'd just read the other day that explains git's three different trees.

About johnny

Computers have interested me since I can remember and conveniently I studied computer science. I also enjoy performing in a local amateur theatre group and cycling. This is where I post solutions to problems I've had in the office or any other project, hopefully clearly enough to refer back to in the future.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>