From 5e68fb8c647d5394017552637250f89d9cbf8993 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sat, 24 Feb 2024 17:47:19 -0600 Subject: [PATCH] Add Interactively Checkout Specific Files From A Stash as a Git TIL --- README.md | 3 ++- ...ely-checkout-specific-files-from-a-stash.md | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 git/interactively-checkout-specific-files-from-a-stash.md diff --git a/README.md b/README.md index f12190a..40ebd63 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://crafty-builder-6996.ck.page/e169c61186). -_1377 TILs and counting..._ +_1378 TILs and counting..._ --- @@ -291,6 +291,7 @@ _1377 TILs and counting..._ - [Include Or Exclude Remaining Patch Changes](git/include-or-exclude-remaining-patch-changes.md) - [Include Some Stats In Your Git Log](git/include-some-stats-in-your-git-log.md) - [Intent To Add](git/intent-to-add.md) +- [Interactively Checkout Specific Files From A Stash](git/interactively-checkout-specific-files-from-a-stash.md) - [Interactively Unstage Changes](git/interactively-unstage-changes.md) - [Keep File Locally With `git rm`](git/keep-file-locally-with-git-rm.md) - [Last Commit A File Appeared In](git/last-commit-a-file-appeared-in.md) diff --git a/git/interactively-checkout-specific-files-from-a-stash.md b/git/interactively-checkout-specific-files-from-a-stash.md new file mode 100644 index 0000000..16bd850 --- /dev/null +++ b/git/interactively-checkout-specific-files-from-a-stash.md @@ -0,0 +1,18 @@ +# Interactively Checkout Specific Files From A Stash + +This command will prompt you with a list of the stashes in your current git +repo. Once you select one of them from the interactive fzf prompt, you will +then be prompted with another fzf prompt, this second one allow multi-select. +From there you can tab select the files you want to checkout. Once you've +marked the ones you want, hit enter and those files will be checked out to your +index. + +```bash +git stash show --name-only $( + git stash list \ + | fzf --height=20% --reverse \ + | sed 's/:.*//' +) \ +| fzf --height=20% --multi --sync \ +| xargs -I {} sh -c 'git checkout stash@{0} -- {}' +```