Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Removing invisible Icon files on a local repository on a Mac

Henrique Tavares May 7, 2013

I am having several erros when commiting or trying to delete folders on my local repository, because of the invisible icon files that sometimes the OS throughs.

I suppose it's because of the file's name that contains a line return, and it bothers SourceTree.

Any way to remove these files from a repository without any errors?

One example of an error here:

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

Because of this, all my commits need to be done almost file by file (or selecting all and deselecting the icon files).

OS X 10.8.3, SourceTree 1.5.8, git or Hg.

10 answers

1 accepted

3 votes
Answer accepted
--marc August 2, 2014

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

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

WORKAROUND: adding icon* pattern in the .gitignore file will work to have "Iconr" files ignored in SourceTree.

CAVEAT: Since * is a wild card, all other files which begin with "Icon" will also be ignored. So, if you have icon_16x16.png, it will need to be renamed to something like my_icon_16x16.png.

UPDATE: icon? (thank you Jack James) is an improvement over icon* because the ? is a single character wildcard. So, files like "Icon\r", "icona" and "icon3" will be ignored with an icon? pattern.

icon? convenient and sufficient for many use cases.

UPDATE2: Advanced, but specific to Iconr file name. Hack the .gitignore with interactive ruby or 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.   

In interactive ruby in the OSX Terminal application,

osx> cd /path/to/.gitignore
osx> irb # start interactive ruby session
ruby> f = File.open(".gitignore", "a+") # append
ruby> f.write("\n# REMINDER: do not edit Icon^M^M Carriage Returns\n") #
ruby> f.write("Icon\r\r") # Icon with 0x0d 0x0d (aka ^M ^M or CR CR)
ruby> f.write("\n# END REMINDER\n") #
ruby> f.close
ruby> exit # quit interactive ruby session

Note 2a: quit and restart SourceTree to see the changes take affect.

Note 2b. 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 2c: Empirically, the double \r\r are required. (Not sure why) Be careful not to delete either \r. Adding comments before and after can help you remember.

Update2 Source Credit: @j dlx and http://blog.bitfluent.com/post/173740409/ignoring-icon-in-gitignore

Henrique Tavares December 5, 2014

I approved your answer rather than Jack James because you gave a more detailed explanation, thanks.

Like jonathanporter likes this
6 votes
surrealroad
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 14, 2014

adding icon? to .gitignore works

Henrique Tavares December 5, 2014

Thank you!

1 vote
j dlx December 10, 2014
Henrique Tavares December 10, 2014

very nice one!

j dlx December 10, 2014

dang.. just doesn't work here.. =8-;

Michael N
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 11, 2015

Hm, it doesn't work for me. I've used icon? instead.

1 vote
m
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2013

You might want to set up a .gitignore file for the future.

Henrique Tavares May 17, 2013

Great idea! thanks

0 votes
Jelle Alten
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 15, 2021

This is a much easier solution:

echo -e "Icon\xd\xd" >> ~/.gitignore_global

0 votes
j dlx December 10, 2014

@–marc: osx terminal actually is pretty indecisive.. ;) `ls` says:

-rw-r--r--@ 1 adm admin 0 10 Dez 19:04 Icon?

, however tab completion says:

adm$ mv Icon^M

go figure.. ;)

--marc December 10, 2014

agreed. I found the autocomplete ^M to be a 0x0D CR Carriage Return. Old Mac OS 9 line separator, used in OSX for the Icon\r file name. A puzzle remains as to why Icon^M^M works in .gitignore, but Icon^M with is single ^M fails for me.

j dlx December 10, 2014

As puzzling as why Icon^M^M doesn't work for me in the first place.. ;) maybe it's 'cause i'm on 10.6.8..

0 votes
Rodrigo Munoz
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 5, 2014

This works like a charm! Thank you, Marc!

0 votes
Dennis Nyström
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 25, 2014

Same issue here.
Would love a fix/tips for this.

0 votes
benoitfreslon March 16, 2014

Hello,

I got the same problem.

Did you found a workaround?

Thanks ;)

0 votes
KieranA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2013

Hi Henrique,

I'm not sure what command you issued, perhaps git rm, but you cannot issue the parameter against a folder, it has to be files. You should issue a wildcard, i.e. images/Iconr/* instead. The error does look confusing, but it's just saying the specification of the path you provided isn't matching any files, and Git works with files.

Hope that helps!

Henrique Tavares May 17, 2013

I'm trying to remove that file not the folder, but as you may or may not know, these icon files have a realy painfull to use filename (with a paragraph!) and SourceTree doesn't handle it. The error says it doesn't match a file because the filename used by SourceTree isn't the same as the one in the real file/file in the repository.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events