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?
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