Remove weird 'Iconr' file from the repository

南楼画角 提交于 2019-12-17 18:27:12

问题


In my git repository I've got a weird file in the staging area that's refusing to be reverted, removed, committed - basically I can't make it go away..

The file must be some ancient OS 9 file sitting there in the folder for years.

Couple days ago I've removed the file in the file system so now git is tracking the deletion of Iconr.

However, it's stuck there.

The error I'm getting via SourceTree (my git UI client) is

fatal: pathspec 'folder/Iconr' did not match any files

Any idea how to make git completely forget about that file?


回答1:


It is best to revert to the command line in order to have a more precise error message.

There you can try a git add -u, followed by a git commit, in order to register the deletion of that file in the repo.
See "git status says file is deleted but git rm says error: pathspec '…' did not match any files" as an example.

You can also preview what a git clean would give: git clean -d -x -n (as explained in "Why is there no “pathspec” when I try to remove a folder in Git?")

The other issue is when that file isn't tracked at all in your current branch, but is tracked in another branch. See that answer to check if that is the case.




回答2:


Adding a line

Icon?

to .gitignore worked for me.

https://answers.atlassian.com/questions/167170/removing-invisible-icon-files-on-a-local-repository-on-a-mac




回答3:


As a general workaround the .gitignore file can be edited to completely ignore the Icon\r files as described in this blog entry: Git Tip: Ignoring Icon\r in .gitignore




回答4:


The Icon^M-like files most likely are created by some external apps such as Folderol which are highlighting your folders.

You should either remove the app which is doing that, or ignore it in your .gitignore file, e.g.

printf "Icon\r\r" >> .gitignore

This is a shell command. Or add it as Icon?? or you can reproduce ^M special character by Control-V and hitting Enter.

Related: How to ignore Icon? in git

If you don't want to commit this change into your repository, alternatively add it into your global .gitignore or add it into .git/info/exclude.

See: Using Git / Ignoring files.

To remove the files it-self, try:

find . -type f -name 'Icon?' -print -delete

Or if they're the only one which are unstaged, run: git clean -f.




回答5:


What shows as "Iconr" in SourceTree is really "Icon\r" where \r is the hex value 0x0d.

.gitignore filename pattern matching is limited compared to POSIX regex. Regular expression patterns such as "Icon\r" and "Icon\x0d" did not work for me with SourceTree.

Simple Ignore: add Icon? pattern in the .gitignore file will work to have "Iconr" files ignored in SourceTree.

_Caveat: Icon? uses ? which is a single character wildcard. So, files and folders like "Icon\r", "icona", "icon3" and "Icons" will be ignored with an Icon? pattern. So, if needed, use file names Icon01, icon02, iconaa instead of Icon1, icon2, icona with this workaround to add such files to git._

Precise Ignore: The precise Iconr filename can be ignored with a binhex editor.

In binhex editor, add 0a 49 63 6e 6e 0d 0d 0a. The extra 0a's are linefeeds to bracket the 'Icon\r\r' for later editing of an otherwise unix file.

Caveat: If using the precise 49 63 6e 6e 0d, be careful to not replace \r with \n. In other words, do not edit .gitignore in a text editor set to autoreplace line separators with this approach.

Note: The Simple Ignore Icon? is convenient and sufficient for most use cases. Quit and restart SourceTree to see the changes take affect. macOS git is case insensitive by default.

Custom Folder/File Icons: A "Icon\r" file is created each time a custom icon is added to a folder or file. For example, the custom icon can added via the Get Info window. Here is an example where the default system folder icon has been replaced with a custom folder icon.

The "Icon\r" file(s) can be removed manually via the file/folder Get Info window or by invoking a shell command to remove the "Icon\r" files ... as noted by kenorb's answer.




回答6:


You can ignore the Icon? on any level of subfolders using wildcards:

// .gitignore
**/Icon?

Wildcards works since version 1.8.2 of git



来源:https://stackoverflow.com/questions/22589978/remove-weird-iconr-file-from-the-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!