Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore Icon? in git

Tags:

git

macos

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.

like image 502
taiansu Avatar asked Jul 09 '13 19:07

taiansu


People also ask

How do I ignore something in git?

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.

How do I force git to ignore a 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.


Video Answer


4 Answers

You can use vim as well.

  1. vim .gitignore
  2. in a new line write Icon, then
  3. press ctrl+v and then press Enter
  4. repeat step 3
  5. 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.

like image 60
Dharma Avatar answered Oct 17 '22 06:10

Dharma


(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.

like image 29
eldes Avatar answered Oct 17 '22 06:10

eldes


"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.

like image 41
hidn Avatar answered Oct 17 '22 06:10

hidn


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

like image 30
rjatkinson Avatar answered Oct 17 '22 06:10

rjatkinson