'.gitignore not ignoring previously commited file in subdirectory despite *.<fileending>

After having forgotten to include it in my .gitignore file, the file 'Labb1.mpf' was accidentally commited and sent upstream. Afterwards I added the line '*.mpf' into my gitignore file, but the file still showed up under 'Untracked Files' when I ran git status and became staged when I used 'git add .'. It was still in untracked files even after a commit which removed the file upstream. Labb.mpf is in a subdirectory with this structure:

C:.
│   .gitignore
|
└───Labb1
    │   Labb1.mpf

I eventually managed to make it not get included in 'git add .' by specifically writing out the full pathname in the gitignore file.

Labb1/Labb1.mpf

If I comment out this line and only run '*.mpf', the file become staged with the git add command again.

This is a solution in a way, but I don't know why and it is not a very elegant solution for a problem that may very well come up in other circumstances. Do anyone have any ideas as to how to use the asterisk command to successfully ignore, in this case, .mpf files?

I have tried with both one and two asterisks.

(Update) Solution:

Thanks to the tip from VonC, I got to know that any whitespace after a .gitignore declaration makes the statement fail. I had the '.mpf' statement written like this

*.mpf #Remove project definition file

were as you can see, there is a whitespace between the statement and the comment. By moving the comment to a separate line (and removing the whitespace), the statement did as intended.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source