File tree 2 files changed +29
-1
lines changed
2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
10
10
11
11
For a steady stream of TILs, [ sign up for my newsletter] ( https://crafty-builder-6996.ck.page/e169c61186 ) .
12
12
13
- _ 1503 TILs and counting..._
13
+ _ 1504 TILs and counting..._
14
14
15
15
---
16
16
@@ -297,6 +297,7 @@ _1503 TILs and counting..._
297
297
- [ Configure Global gitignore File] ( git/configure-global-gitignore-file.md )
298
298
- [ Configuring The Pager] ( git/configuring-the-pager.md )
299
299
- [ 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 )
300
301
- [ Create A New Branch With Git Switch] ( git/create-a-new-branch-with-git-switch.md )
301
302
- [ Delete All Untracked Files] ( git/delete-all-untracked-files.md )
302
303
- [ Determine The Hash Id For A Blob] ( git/determine-the-hash-id-for-a-blob.md )
Original file line number Diff line number Diff line change
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.
You can’t perform that action at this time.
0 commit comments