The only difference between the .gitignore is a space at the beginning of a line, and it seems to make the line ignored. Why is the result different. I add the space for alignment.

I expect the outcome should be the same.
The wrong intuition may come from this rule which says nothing about beginning space. I did see the word trailing though.
Trailing spaces are ignored unless they are quoted with backslash ("\").
>Solution :
The difference between d1/* and d1/* is that the first ignores everything under the folder named d1 and the second ignores everything under the ' d1' folder.
The reasoning behind this is that folders can start with blank spaces.
So those two .gitignore files are matching different folders. Hence why the second one includes everything under d1 folder.