Git结帐/删除带有特殊字符的文件 [英] Git checkout/remove file with special characters

查看:180
本文介绍了Git结帐/删除带有特殊字符的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文件名(umlauts)中有一个带有特殊字符的文件。我既然已经重命名了这个文件,但是 git 仍然告诉我我的'变更没有进行提交'。但是,我不记得文件的正确名称,而git只告诉我名称是Mu \314\210.jpg。我不知道应该是什么格式。 UTF8 ?我尝试了 git rm 并复制了字符串,但没有成功。



如何找出原始文件的名称或如何删除文件而不知道确切的文件名(也许只有文件扩展名)?

编辑:我开始有这种感觉该文件是在Windows PC上创建的,其中的变音编码不同。然而,我无法解释为什么我无法删除文件。



我刚发现那些是八进制表示。尝试从无法删除目录git 从git中删除一个具有奇怪名称的文件,以及,但是,没有帮助。尤其是解决方案

  git rm`printfMu\314\210.jpg`

并未删除该文件。它仍然给我Mu \314\210.jpg与任何文件不匹配。有没有其他方法可以删除文件?



printf 告诉我Mu \314\210.jpgMü.jpg。但是,我的Mac OSX上的ü八进制表示应该是 \303\274 。这就是为什么我认为 u \314\210 来自Windows PC的原因。我还试图运行 git-rm 建议的内容<$ c $ c> git diff --name-only --diff-filter = D -z | xargs -0 git rm --cached 。我很安静,现在该文件不能删除,直到它再次被添加。我将尝试使用旧文件名获取文件,然后将其删除。



好的,添加旧文件也没有帮助。 Mac OSX似乎会自动更改八进制表示法。看起来像是最后一次在Windows PC上删除它。

  git rm Mu * .jpg 

这将从索引中删除所有文件以Mu开头并以.jpg结尾

如果回购库中的其他文件与该模式相匹配,它们将被删除。在这种情况下,您可以使用:

  git add -u Mu * .jpg 

从git的手册页添加:


- u
--update



只匹配索引中的已经跟踪的文件而不是工作树。这意味着它永远不会
阶段的新文件,但它会逐步修改
跟踪文件的新内容,并且它将从索引中删除文件,如果
工作树中的相应文件已被删除。

(这也将在与该模式匹配的文件中完成存储库中的任何其他更改,如果您想要使用 git reset


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.

解决方案

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)

这篇关于Git结帐/删除带有特殊字符的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆