Skip to content

Commit 1c4e37e

Browse files
committed
Add Count All Files Of Specific Type Tracked By Git as a Git TIL
1 parent 581aa1d commit 1c4e37e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
1212

13-
_1503 TILs and counting..._
13+
_1504 TILs and counting..._
1414

1515
---
1616

@@ -297,6 +297,7 @@ _1503 TILs and counting..._
297297
- [Configure Global gitignore File](git/configure-global-gitignore-file.md)
298298
- [Configuring The Pager](git/configuring-the-pager.md)
299299
- [Copy A File From Another Branch](git/copy-a-file-from-another-branch.md)
300+
- [Count All Files Of Specific Type Tracked By Git](git/count-all-files-of-specific-type-tracked-by-git.md)
300301
- [Create A New Branch With Git Switch](git/create-a-new-branch-with-git-switch.md)
301302
- [Delete All Untracked Files](git/delete-all-untracked-files.md)
302303
- [Determine The Hash Id For A Blob](git/determine-the-hash-id-for-a-blob.md)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Count All Files Of Specific Type Tracked By Git
2+
3+
I want to get a count of all the markdown files in my [TIL
4+
repo](https://github.com/jbranchaud/til). Since all the files I care about are
5+
tracked by `git`, I can use `git ls-files` to get a listing of all files. That
6+
command on its own lists all files tracked by your git repository. Though there
7+
are many other flags we can apply, that will do for my purposes.
8+
9+
By giving `git ls-files` a pattern to match against, I can turn up just, for
10+
instance, markdown files (`*.md`). I can pipe that to `wc -l` to get a count
11+
rather than exploding my terminal with a list of file names.
12+
13+
```bash
14+
❯ git ls-files '*.md' | wc -l
15+
1503
16+
```
17+
18+
That command includes `README.md` and `CONTRIBUTING.md`, but really I only want
19+
to count the markdown files that constitute a TIL. Those all happen to be
20+
nested under a single directory. So I can tweak the glob pattern like so:
21+
22+
```bash
23+
❯ git ls-files '*/*.md' | wc -l
24+
1501
25+
```
26+
27+
See `man git-ls-files` for more details.

0 commit comments

Comments
 (0)