From 51c3738c8cde54f1e7efc35d6464ab64b3dc2f6b Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sat, 9 Jan 2021 15:11:43 -0600 Subject: [PATCH] Add Pick Specific Changes To Stash as a git til --- README.md | 3 ++- git/pick-specific-changes-to-stash.md | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 git/pick-specific-changes-to-stash.md diff --git a/README.md b/README.md index 875fae2..9c791a2 100644 --- a/README.md +++ b/README.md @@ -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). -_1000 TILs and counting..._ +_1001 TILs and counting..._ --- @@ -250,6 +250,7 @@ _1000 TILs and counting..._ - [List Most Git Commands](git/list-most-git-commands.md) - [List Untracked Files](git/list-untracked-files.md) - [Move The Latest Commit To A New Branch](git/move-the-latest-commit-to-a-new-branch.md) +- [Pick Specific Changes To Stash](git/pick-specific-changes-to-stash.md) - [Pulling In Changes During An Interactive Rebase](git/pulling-in-changes-during-an-interactive-rebase.md) - [Quicker Commit Fixes With The Fixup Flag](git/quicker-commit-fixes-with-the-fixup-flag.md) - [Rebase Commits With An Arbitrary Command](git/rebase-commits-with-an-arbitrary-command.md) diff --git a/git/pick-specific-changes-to-stash.md b/git/pick-specific-changes-to-stash.md new file mode 100644 index 0000000..c6eb086 --- /dev/null +++ b/git/pick-specific-changes-to-stash.md @@ -0,0 +1,22 @@ +# Pick Specific Changes To Stash + +If you run `git stash`, all of the changes to tracked files on the working tree +will be put into a commit-like entity in the stash list. + +If you want to be a bit choosier about what gets saved during a stash, you can +include the `--patch` flag. + +> With --patch, you can interactively select hunks from the diff between HEAD +> and the working tree to be stashed. + +```bash +$ git stash --patch +``` + +Once in the interactive mode initiated by `--patch`, you'll be presented with a +change of changes and some options. You hit `y` for "yes, include this" and `n` +for "no, don't include that". And then there are some more advanced options +which you can read about in the _Interactive Mode_ section of `git-add`'s man +page. + +See `man git-stash` for more details.