How to ignore Icon? in git
While trying to setup a dropbox folder with git, I saw a "Icon\r" file which is not created by me. I try to ignore it in the ~/.gitignore file. But adding Icon\r
Icon\r\r
Icon?
won't work at all.
You can use vim as well.
vim .gitignore
- in a new line write
Icon
, then - press ctrl+v and then press Enter
- repeat step 3
- save and exit (shortcut: ZZ)
Now you should have Icon^M^M
and it's done :)
For a smarter use you could add it to your gitignore global config file in ~/.gitignore_global
.
(This improves on the original answer, following a suggestion by robotspacer, according to hidn's explanation.)
The Icon?
is the file of OS X folder icon. The "?
" is a special character for double carriage return (\r\r
).
To tell git
to ignore it, open a terminal and navigate to your repository folder. Then type:
printf "Icon\r\r" >> .gitignore
If the file does not exist, it will be created and Icon\r\r
will be its one line. If the file does exist, the line Icon\r\r
will be appended to it.
"Icon[\r]"
is probably a better alternative.
In vim, you just put Icon[^M]
, which is Icon[
followed by CtrlV, Enter then ]
.
The problem with "Icon\r\r"
is EOL conversion.
The whole line is actually "Icon\r\r\n"
, counting line ending. Based on your setup, CRLF
may be converted to LF
on commit, so your repo will actually have "Icon\r\n"
. Say you sync the changes to another repo. You will get "Icon\r\n"
in that working directory, which ignores Icon
but not Icon^M
. If you further edit .gitignore
and commit it there, you will end up with "Icon\n"
- completely losing \r
.
I encountered this in a project where some develop on OS X while some on Windows. By using brackets to separate \r
and the line ending, I don't have to repeat \r
twice and I don't worry about EOL conversion.