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.
Git folder tree structure:
.
└── d1
├── d11
│ ├── f1
│ └── f2
├── d12
│ ├── f1
│ └── f2
└── f1
First .gitignore:
/*
!d1
d1/*
!/d1/d11
First stageable files:
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: d1/d11/f1
new file: d1/d11/f2
Second .gitignore: (notice the difference in the third rule)
/*
!d1
d1/*
!/d1/d11
Second stageable files:
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: d1/d11/f1
new file: d1/d11/f2
new file: d1/d12/f1
new file: d1/d12/f2
new file: d1/f1
Here is the image of my execution 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 ("\").
CodePudding user response:
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.