# Strange behaviour with git-add, .gitignore and a tracked file

2 messages from 2011-12-16 to 2011-12-16. Participants: David ‘Bombe’ Roden, Junio C Hamano.
Thread: https://gitlist.dev/t/29188

## David ‘Bombe’ Roden, 2011-12-16 21:57

Subject: Strange behaviour with git-add, .gitignore and a tracked file
Message-ID: <201112162258.04661.bombe@pterodactylus.net>
URL: https://gitlist.dev/e/201112162258.04661.bombe%40pterodactylus.net

```
Hi.

I stumbled across some strange behaviour today:

---
git init git-test
cd git-test
echo '*' > .gitignore
git add -f .gitignore
git commit -m "Add gitignore."
mkdir dir
echo a > dir/file
git add -f dir/file
git commit -m "Add dir/file."
echo b >> dir/file
git add dir/file
---

The last git-add results in the following error message:

---
The following paths are ignored by one of your .gitignore files:
dir
Use -f if you really want to add them.
fatal: no files added
---

While it is true that the file specification matches a pattern in .gitignore, 
the file is already tracked and should not be ignored.

This behaviour was reproduced with 1.7.7.4 (on OS X), 1.7.5.4, 1.7.1, 
1.7.8-247-g10f4eb6 (latest master as of a couple of hours ago) (all Linux).


Greetings,

	David
-- 
David ‘Bombe’ Roden <bombe@pterodactylus.net>

```

## Junio C Hamano, 2011-12-16 23:42

Subject: Re: Strange behaviour with git-add, .gitignore and a tracked file
Message-ID: <7vmxasf5i1.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vmxasf5i1.fsf%40alter.siamese.dyndns.org
In-Reply-To: <201112162258.04661.bombe@pterodactylus.net>

```
David ‘Bombe’ Roden  <bombe@pterodactylus.net> writes:

> This behaviour was reproduced with 1.7.7.4 (on OS X), 1.7.5.4, 1.7.1, 
> 1.7.8-247-g10f4eb6 (latest master as of a couple of hours ago) (all Linux).

Doesn't that suggest perhaps it could be a designed behaviour?

Perhaps to help users to realize that their .gitignore pattern may want to
be improved?

```
