1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 15:18:01 +00:00

Add Add Only Tracked Files From A Directory as a Git TIL

This commit is contained in:
jbranchaud
2024-05-01 09:31:52 -05:00
parent c06bb2ea7b
commit 01c9c0d19b
2 changed files with 28 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).
_1423 TILs and counting..._
_1424 TILs and counting..._
---
@@ -261,6 +261,7 @@ _1423 TILs and counting..._
- [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)
- [Add Only Tracked Files From A Directory](git/add-only-tracked-files-from-a-directory.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,26 @@
# Add Only Tracked Files From A Directory
The two extremes of staging files in a git repo are to either selectively pick
each individual chunk of changes with `git add --patch` (my preference!) or to
run `git add -A` to add everything.
Now let's say I have large directory full of files that get generated during
test runs. Most of these files are tracked (already checked in to the
repository). There are also many new files generated as part of the most recent
test run.
I want to staging the changes to files that are already tracked, but hold off
on doing anything with the new files.
Running `git add spec/cassettes` won't do the track because that will pull in
everything. Running `git add --patch spec/cassettes` will take long and be
tedious. Instead what I want is the `-u` flag. It's short for _update_ which
means it will only stage already tracked files.
```bash
$ git add -u spec/cassettes
```
That will stage every change to any already known files in `spec/cassettes`.
See `man git-add` for more details.