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.
If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
Use Git update-index to ignore changes Or, you can temporarily stop tracking a file and have Git ignore changes to the file by using the git update-index command with the assume-unchanged flag.
You can use vim as well.
vim .gitignore
Icon
, thenNow 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.
The best place for this is in your global gitignore configuration file. You can create this file, access it, and then edit per the following steps:
>> git config --global core.excludesfile ~/.gitignore_global
>> vim ~/.gitignore_global
press i to enter insert mode
type Icon
on a new line
while on the same line, ctrl + v, enter, ctrl + v, enter
press esc, then shift + ; then type wq then hit enter
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With