Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove a file with a strange name from git

Tags:

git

I have a file that managed to get itself named:

# file's name (both lines)
companies.yml
companies.yml

# entry in my git working tree
"test/fixtures/companies.yml\342\200\250companies.yml"

For annoying reasons, the working tree on this particular project is full of other files that still need organizing. I would like to get the above entry out of there, but when I try git add "test/fixtures..." or git rm "test/fixtures..." it fails:
fatal: pathspec 'test/fixtures/companies.yml\342\200\250companies.yml' did not match any files

How can I deal with this?


Git status

On branch master
# Your branch is ahead of 'production/master' by 4 commits.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)

modified:   [other files]
modified:   "test/fixtures/companies.yml\342\200\250companies.yml"
like image 317
sscirrus Avatar asked Nov 06 '12 12:11

sscirrus


1 Answers

Git is printing the literal octets of the UTF-8 encoding of the filename because they are non-ASCII characters, and printing them as octal escapes. However, your shell does not understand them and is sending literal backslashes and digits to the git command when you cut and paste, so you're actually entering a different filename.

Either use tab-completion after typing test/fixtures/companies.yml (if your shell supports this) which will enter the actual characters or a wildcard in place of the escapes thus test/fixtures/companies.yml*companies.yml. The latter might, but probably won't, match other filenames.

Another possibility is to just rename the file to something more sane, of course, and then use git add -u / git add . to get git to notice the rename.

like image 93
pndc Avatar answered Oct 17 '22 08:10

pndc