Reputation: 345
I had a file with special characters in the file name (umlauts). I since have renamed the file, but git
still tells me that I have 'Changes not staged for commit'. However, I can't remember the correct name of the file, and git only tells me the name is "Mu\314\210.jpg"
. I have no clue what format that is suppose to be. utf8
? I tried git rm
and copied the string, but didn't work.
How can I find out the original name of the file or how can I remove the file without knowing the exact file name (maybe with only the file extension)?
EDIT: I start to have the feeling that the file was created on a Windows PC and the encoding of the umlauts are different there. However, I can't explain why I am not able to remove the file.
I just found out that those are octal representations. Trying out the solutions from Can't remove directories git, Remove a file with a strange name from git, and Git: how to specify file names containing octal notation on the command line, however, didn't help. Especially the solution
git rm `printf "Mu\314\210.jpg"`
didn't delete the file. It still gives me "Mu\314\210.jpg" didn't match any files
. Is there some other way to remove a file?
printf
told me that "Mu\314\210.jpg"
is "Mü.jpg"
. However, the ü
octal representation on my Mac OSX should be \303\274
. That's why I suppose that the u\314\210
comes from a Windows PC. Still not sure how that helps though.
I just tried to run what the git-rm
suggests git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached
. I am quiet positive now that the file can't be removed until it has been added again. I will try to get the file with the old file name and remove it then.
Ok, adding the old file didn't help either. Mac OSX seems to automatically change the octal representation. Seems like the last chance is it remove it on a Windows PC.
Upvotes: 11
Views: 11612
Reputation: 3181
Using git rm you can do :
git rm Mu*.jpg
This will remove from the index all files Starting with Mu and ending with .jpg
If you have other files in the repo that match the pattern they will be removed to. In that case, you can use :
git add -u Mu*.jpg
from the man page of git add :
-u --update
Only match against already tracked files in the index rather than the working tree. That means that it will never stage new files, but that it will stage modified new contents of tracked files and that it will remove files from the index if the corresponding files in the working tree have been removed.
(This will also stage any other change in the repository done in files matching the pattern, you can always unstage them after if you want using git reset
)
Upvotes: 9