Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git ignoring icon files because of Icon? rule

Tags:

git

gitignore

I have a repo that includes SVG images in an icons/ directory. Attempting to add these images to the repo fails, and Git complains with the error message:

The following paths are ignored by one of your .gitignore files:
public/img/icons/my-icon.svg
Use -f if you really want to add them.

When I traced the ignored files using git-check-ignore, I found that the Icon? rule from my .gitignore_global file was the culprit.

$ git check-ignore -v public/img/icons/my-icon.svg 
/Users/ryanatallah/.gitignore_global:42:Icon?   public/img/icons/my-icon.svg

What might be an elegant solution to this problem?

like image 285
Ryan Atallah Avatar asked Jan 14 '14 09:01

Ryan Atallah


2 Answers

Turns out this problem is caused by a Git bug where the Icon? gitignore rule also matches directories such as icons/. The solution is to write the rule with the correct control character (which is a carriage return) at the end. This question explains that Icon? files are automatically created for directories with custom icons.

The solution, as documented in this blogpost is to correctly write the rule to my global gitignore file with the carriage return. The following Ruby script does the trick:

>> f = File.open(".gitignore", "a+") # append
=> #<File:.gitignore>
>> f.write("Icon\r\r")
=> 8
>> f.close
=> nil 
like image 190
Ryan Atallah Avatar answered Sep 22 '22 07:09

Ryan Atallah


To override rules from the parent .gitignore file you need to use ! prefix, for example add in local .gitignore file:

!Icon
like image 37
Wojciech Bednarski Avatar answered Sep 23 '22 07:09

Wojciech Bednarski