# Buggy (or undocumented) handling of terminal \r in .gitignore patterns

2 messages from 2008-12-03 to 2008-12-03. Participants: Aaron Harnly, Michael J Gruber.
Thread: https://gitlist.dev/t/16580

## Aaron Harnly, 2008-12-03 15:46

Subject: Buggy (or undocumented) handling of terminal \r in .gitignore patterns
Message-ID: <loom.20081203T152511-351@post.gmane.org>
URL: https://gitlist.dev/e/loom.20081203T152511-351%40post.gmane.org

```
This is with git 1.5.6.3 on Ubuntu and Mac OS X.

Overview: .gitignore patterns ending in \r do not work as expected, apparently
because the terminal \r is assumed to be part of the newline.

Steps to Reproduce:
(NB ^M is the control-M sequence, not a literal caret-M)

1. Create an empty repository.
2. Create a file named Icon\r (aka Icon^M).
3. Add the following pattern to the .gitignore:

Icon^M

Expected behavior:

The file is ignored.

Actual behavior:

The file is not ignored.

Discussion:

It appears that the parsing of .gitignore files tries to be graceful in allowing
the file to have CRLF endings, or indeed mixed LF / CRLF endings.

This is well and good, but poses a bit of a problem for ignoring files whose
name ends in \r. In particular, Mac OS X's icon files are named Icon\r. Yes,
this is sick and annoying on the part of Apple.

I understand the rationale for this behavior, but it probably should be
documented somewhere. In the meantime, a workaround that does allow the ignoring
of these files is the pattern:

Icon^M^M

where again, the terminal \r seems to be ignored as part of the newline, but the
penultimate \r gets picked up as part of the pattern.

Any thoughts on whether:
1. this behavior should be left as it is
2. there is actually documentation somewhere that I didn't see
3. terminal \r in an otherwise all-LF file should be assumed to be part of the
pattern
4. some other alternative?

cheers,
~aaron

```

## Michael J Gruber, 2008-12-03 17:42

Subject: Re: Buggy (or undocumented) handling of terminal \r in .gitignore patterns
Message-ID: <4936C4F3.70501@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4936C4F3.70501%40drmicha.warpmail.net
In-Reply-To: <loom.20081203T152511-351@post.gmane.org>

```
Aaron Harnly venit, vidit, dixit 03.12.2008 16:46:
> This is with git 1.5.6.3 on Ubuntu and Mac OS X.
> 
> Overview: .gitignore patterns ending in \r do not work as expected, apparently
> because the terminal \r is assumed to be part of the newline.
> 
> Steps to Reproduce:
> (NB ^M is the control-M sequence, not a literal caret-M)
> 
> 1. Create an empty repository.
> 2. Create a file named Icon\r (aka Icon^M).
> 3. Add the following pattern to the .gitignore:
> 
> Icon^M
> 
> Expected behavior:
> 
> The file is ignored.
> 
> Actual behavior:
> 
> The file is not ignored.
> 
> Discussion:
> 
> It appears that the parsing of .gitignore files tries to be graceful in allowing
> the file to have CRLF endings, or indeed mixed LF / CRLF endings.
> 
> This is well and good, but poses a bit of a problem for ignoring files whose
> name ends in \r. In particular, Mac OS X's icon files are named Icon\r. Yes,
> this is sick and annoying on the part of Apple.
> 
> I understand the rationale for this behavior, but it probably should be
> documented somewhere. In the meantime, a workaround that does allow the ignoring
> of these files is the pattern:
> 
> Icon^M^M
> 
> where again, the terminal \r seems to be ignored as part of the newline, but the
> penultimate \r gets picked up as part of the pattern.
> 
> Any thoughts on whether:
> 1. this behavior should be left as it is
> 2. there is actually documentation somewhere that I didn't see
> 3. terminal \r in an otherwise all-LF file should be assumed to be part of the
> pattern
> 4. some other alternative?

5. spank Apple

```
