Can anyone explain to me clearly the difference between using the commands below in the .gitignore file?
-
/pasta
-
pasta/
Can anyone explain to me clearly the difference between using the commands below in the .gitignore file?
/pasta
pasta/
You know you can by .gitignore
in any subfolder of the project git tag ? It took me a few years to figure this out, and I was happy with the discovery.
The first case, pasta/
, does not require the folder to be in the same directory as .gitignore
. It can be any subdirectory called pasta
that will be ignored.
The second case, /pasta/
forces the directory to be skipped to be in the same folder as .gitignore
. So you can be very specific.
Imagine the following structure:
/--+
|
+- dira/ --+
| |
| +- .gitignore [1]
| +- subdira/ --+
| | |
| | +- pasta/
| +- pasta/
|
+- dirb/--+
| |
| +- .gitignore [2]
| +- subdirb/ --+
| | |
| | +- pasta/
| +- pasta/
+- pasta/
The content of /dira/.gitignore
(indicated by [1]
) is:
pasta/
As for /dirb/.gitignore
(indicated by [2]
) is:
/pasta/
With this, the project will show the differences in the following pasta/
directories:
/dirb/subdirb/pasta/
/pasta/
And ignore the following:
/dira/pasta/
/dira/subdira/pasta/
/dirb/pasta/