You can tell Git to ignore some files or directories using a pattern. However, there are some exceptions we don’t want miss files which are matched to the pattern. In this post, I am going to briefly present how to use an exclamation mark syntax.
The above example instructs Git to ignore all files with the
.txt extension except for files named
If the file is in an ignored folder, you can NOT re-include it so easily:
In this example,
debug.log file in the folder would remain ignored.
The right way is re-include the folder itself on a separate line, then ignore all files in
*, finally re-include the
folder, as the following:
!logs/ logs/* !logs/*.txt
Note: For file names beginning with an exclamation mark, add two exclamation marks or escape with the