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

Add Stash A Single Untracked File as a git til

This commit is contained in:
jbranchaud
2021-03-25 18:41:53 -05:00
parent 3658b4de6d
commit 5f20629060
2 changed files with 38 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://tinyletter.com/jbranchaud).
_1097 TILs and counting..._
_1098 TILs and counting..._
---
@@ -290,6 +290,7 @@ _1097 TILs and counting..._
- [Skip Pre-Commit Hooks](git/skip-pre-commit-hooks.md)
- [Staging Changes Within Vim](git/staging-changes-within-vim.md)
- [Staging Stashes Interactively](git/staging-stashes-interactively.md)
- [Stash A Single Untracked File](git/stash-a-single-untracked-file.md)
- [Stash Everything](git/stash-everything.md)
- [Stashing Only Unstaged Changes](git/stashing-only-unstaged-changes.md)
- [Stashing Untracked Files](git/stashing-untracked-files.md)

View File

@@ -0,0 +1,36 @@
# Stash A Single Untracked File
If you want to stash everything in your work tree and untracked files, you can
run:
```bash
$ git stash -u
```
If you want a bit more control over what gets stashed from the work tree, you
can interactively stash with `--patch` (or `-p`):
```bash
$ git stash -p
```
Unfortunately, the two don't work together.
```bash
$ git stash -u -p
Can't use --patch and --include-untracked or --all at the same time
```
So, if you'd like to stash a specific untracked file, you can instead formulate
a command like the following:
```bash
$ git stash -u -- <name-of-untracked-file>
```
This will stash just the specified untracked file and leave the rest of them as
they are.
I found this useful when trying to test the setup of a new library. There was
an extra new file that I didn't think I needed. Stashing it temporarily gets it
out of the way without losing it.