1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-02 22:58:01 +00:00

Add Add A Range Of Filenames To gitignore as a Git TIL

This commit is contained in:
jbranchaud
2022-10-01 11:09:29 -05:00
parent 0dc97cbbcb
commit 9e7f0221b9
2 changed files with 36 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1247 TILs and counting..._
_1248 TILs and counting..._
---
@@ -235,6 +235,7 @@ _1247 TILs and counting..._
### Git
- [Accessing a Lost Commit](git/accessing-a-lost-commit.md)
- [Add A Range Of Filename To gitignore](git/add-a-range-of-filenames-to-gitignore.md)
- [Amend Author Of Previous Commit](git/amend-author-of-previous-commit.md)
- [Auto-Squash Those Fixup Commits](git/auto-squash-those-fixup-commits.md)
- [Caching Credentials](git/caching-credentials.md)

View File

@@ -0,0 +1,34 @@
# Add A Range Of Filenames To gitignore
The `.gitignore` file is a file where you can list files that should be ignored
by git. This will prevent them from showing up in diffs, `git status`, etc.
Most entries in the `.gitignore` file will plainly correspond to a single file.
```
# ignore env var files
.env
.env.local
```
Sometimes a project has a bunch of similarly named files. Autogenerated files
are a prime example. For instance, a web app project may contain several
sitemap files with incrementing suffix values (i.e. `sitemap-1.xml`,
`sitemap-2.xml`, `sitemap-3.xml`, ...).
I'd like to avoid having to type those all out in my `.gitignore` file. And I
don't want to have to add new entries whenever another increment of the file is
generated.
I can handle all the current ones and future ones in a single line using some
range pattern matching supported by the `.gitignore` file format.
```
# ignore sitemap files
public/sitemap-[1-99].xml
```
This will ignore any sitemap files suffixed with 1 to 99. I don't really expect
there to ever be more than handful of those files, so _99_ should definitely do
the trick.
[source](https://www.golinuxcloud.com/gitignore-examples/#5_Examples_of_pattern_matching_in_gitignore)