โปรดทราบว่าพูดอย่างเคร่งครัด git ไม่ได้ติดตามไดเรกทอรี แต่ไฟล์เท่านั้น ด้วยเหตุนี้จึงไม่สามารถเพิ่มไดเร็กทอรีได้มีเพียงเนื้อหาเท่านั้น
อย่างไรก็ตามในบริบทของ.gitignoregit แสร้งทำเป็นเข้าใจไดเรกทอรีด้วยเหตุผลเดียวว่า
ไม่สามารถรวมไฟล์อีกครั้งได้หากไม่รวมไดเร็กทอรีหลักของไฟล์นั้น
https://git-scm.com/docs/gitignore#_pattern_format
นี่หมายความว่าอย่างไรสำหรับรูปแบบการยกเว้น มาดูรายละเอียดกัน:
bin
สิ่งนี้ละเว้น
- ไฟล์ชื่อ
bin.
- เนื้อหาของโฟลเดอร์ที่ชื่อ
bin
คุณสามารถกำหนดbinไฟล์และโฟลเดอร์ที่ถูกละเว้นได้โดยการเพิ่ม!รายการที่ตามมาแต่คุณไม่สามารถอนุญาตพิเศษเนื้อหาของโฟลเดอร์ที่ชื่อbin
bin
!bin/file_in_bin # has no effect, since bin/ is blacklisted!
!bin/* # has no effect, since bin/ is blacklisted!
!file_in_bin # has no effect, since bin/ is blacklisted!
!bin # this works
bin/
เหมือนข้างบน แต่มันไม่ตรงกับไฟล์binชื่อ การเพิ่มการต่อท้าย/จะบอกให้คอมไพล์ตรงกับไดเร็กทอรีเท่านั้น
bin/*
สิ่งนี้ละเว้น
- ไฟล์ที่อยู่ในโฟลเดอร์ชื่อ
bin
- เนื้อหาของโฟลเดอร์ย่อยโดยตรงของโฟลเดอร์ที่ชื่อ
bin
bin/* # blacklists bin/file_in_bin and bin/subfolder/
!bin/subfolder/file_in_sub # has no effect, since bin/subfolder is blacklisted!
!bin # whitelists files named bin/bin, since bin/ itself is not blacklisted
!bin/ # has no effect, since bin/ itself is not blacklisted
!bin/file_in_bin # works since bin/ itself is not blacklisted
!file_in_bin # works too
!bin/subfolder # works (so implicitly whitelists bin/subfolder/file_in_sub)
!bin/subfolder/ # works just as well
!bin/* # works for file_in_bin and subfolder/
bin/**
สิ่งนี้ละเว้น
- เนื้อหาของ
bin
- เนื้อหาของโฟลเดอร์ย่อย (ระดับการซ้อนกัน) ภายใน
bin
bin/** # blacklists bin/file_in_bin and
# bin/subfolder/ and bin/subfolder/file_in_sub and
# bin/subfolder/2/ and bin/subfolder/2/file_in_sub_2
!bin/subfolder/file_in_sub # has no effect, since bin/subfolder is blacklisted
!bin/subfolder/2/ # has no effect, since bin/subfolder is blacklisted
!bin/subfolder/2/file_in_sub_2 # has no effect, since bin/subfolder is blacklisted
!bin/subfolder # works only in combinations with other whitelist entries,
# since all contents of subfolder are blacklisted (1)
!bin/file_in_bin # works since bin itself is not blacklisted
!bin/* # works for file_in_bin and subfolder; see (1)