1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-16 05:28:03 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
jbranchaud
ed2e96c126 Add Find And Remove Files That Match A Name as a Git TIL 2022-10-17 17:27:47 -05:00
jbranchaud
0fd6ef25eb Add Seed Production Data Into Another Branch as a Planetscale TIL 2022-10-14 13:01:34 -05:00
3 changed files with 72 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).
_1254 TILs and counting..._
_1256 TILs and counting..._
---
@@ -43,6 +43,7 @@ _1254 TILs and counting..._
* [Netlify](#netlify)
* [Next.js](#nextjs)
* [Phoenix](#phoenix)
* [Planetscale](#planetscale)
* [pnpm](#pnpm)
* [PostgreSQL](#postgresql)
* [Prisma](#prisma)
@@ -261,6 +262,7 @@ _1254 TILs and counting..._
- [Dry Runs in Git](git/dry-runs-in-git.md)
- [Exclude A File From A Diff Output](git/exclude-a-file-from-a-diff-output.md)
- [Excluding Files Locally](git/excluding-files-locally.md)
- [Find And Remove Files That Match A Name](git/find-and-remove-files-that-match-a-name.md)
- [Find The Date That A File Was Added To The Repo](git/find-the-date-that-a-file-was-added-to-the-repo.md)
- [Find The Initial Commit](git/find-the-initial-commit.md)
- [Get The Name Of The Current Branch](git/get-the-name-of-the-current-branch.md)
@@ -557,6 +559,10 @@ _1254 TILs and counting..._
- [Specifying The Digest Directory](phoenix/specifying-the-digest-directory.md)
- [Specifying The Server Port](phoenix/specifying-the-server-port.md)
### Planetscale
- [Seed Production Data Into Another Branch](planetscale/seed-production-data-into-another-branch.md)
### pnpm
- [Execute A Command From The Workspace Root](pnpm/execute-a-command-from-the-workspace-root.md)

View File

@@ -0,0 +1,37 @@
# Find And Remove Files That Match A Name
Let's say I have a bunch of `robots.txt` file scattered throughout my project.
I want to find all instances of that file checked into git. I then want to
remove that file from git.
I can find all the instances of that file checked into git using the
[`git-ls-files`](https://git-scm.com/docs/git-ls-files) command.
```bash
$ git ls-files '**/robots.txt'
project-a/public/robots.txt
project-b/public/robots.txt
apps/project-c/public/robots.txt
```
That results in a list of paths of those files regardless of how far down they
are nested (because of the `**` glob pattern).
And because `git-ls-files` is a _git plumbing_ command, it pipes cleanly into
other unix commands.
I can combine that first command with [`git
rm`](https://git-scm.com/docs/git-rm) using the
[`xargs`](https://man7.org/linux/man-pages/man1/xargs.1.html) command.
```bash
$ git ls-files '**/robots.txt' | xargs git rm
rm 'project-a/public/robots.txt'
rm 'project-b/public/robots.txt'
rm 'apps/project-c/public/robots.txt'
```
That takes each path from the first part of the command and passes it to `git
rm` which stages it as a removed file.
I can finalize my work by creating a commit from these staged changes.

View File

@@ -0,0 +1,28 @@
# Seed Production Data Into Another Branch
When you [create a Planetscale
branch](https://planetscale.com/docs/reference/branch) off `main`, it will only
copy over the schema. No data will be copied over to that new branch.
You can copy data over from the initial branch (`main`) in two steps from the
CLI. First, create a dump of the branch. Then restore the dump into your new
branch.
```bash
$ pscale database dump database-name main --output ./dump
```
That creates SQL files locally in the `dump` folder with both schema and data
statements.
That folder of SQL files can then be restored into one of your branches.
```bash
$ pscale database restore-dump database-name branch-name --dir ./dump --overwrite-tables
```
The `--overwrite-tables` flag is needed because your branch's existing schema
will conflict with the `create` schema statements in the SQL files.
You can `pscale shell` into that branch and run a `select ...` statement to
check out the data.