From aa613f5d95268beeba6cde2d0534d1df92ef3d22 Mon Sep 17 00:00:00 2001 From: Bhupesh-V Date: Sun, 11 Apr 2021 13:16:19 +0530 Subject: [PATCH] undo git stash apply --- README.md | 4 ++-- ugit | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6c027da..11a466f 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,8 @@ - [x] Undo `git reset` - [ ] Undo `git merge` - [ ] Undo `git tag -D` (tag delete) -- [ ] Undo `git stash apply` -- [ ] Undo `git stash drop/clear` +- [x] Undo `git stash apply` +- [x] Undo `git stash drop/clear` ## Installation diff --git a/ugit b/ugit index 90a8ae9..ab337e0 100755 --- a/ugit +++ b/ugit @@ -38,6 +38,7 @@ menu=$(cat << MENU 9 Undo an Unpushed Merge Commit 10 Undo a Pushed Merge Commit 11 Undo stash drop/clear +12 Undo git stash apply MENU ) option=$(echo "$menu" | fzf --height 20% --reverse --pointer='ᐅ' --header='Undo your last oopsie in Git 🙈️' --preview 'git status -s' | awk '{print $1}') @@ -99,6 +100,7 @@ undo_git_merge() { git revert -m 1 "$commit_hash" fi } + recover_lost_stash() { lost_stash_hash=$(git fsck --no-progress --unreachable | grep commit | cut -d ' ' -f3 | xargs git log --oneline --merges --no-walk | awk '{print $1}') read -p "Enter Stash Message/Comment: " -r STASH_MSG @@ -108,6 +110,12 @@ recover_lost_stash() { fi } +undo_git_stash_apply() { + # TODO: check if diff coloring is on in git config otherwise the reverse apply command will fail + # TODO: option to select which stash to unapply? + git stash show -p | git apply --reverse +} + case $option in 1) undo_git_commit;; 2) undo_git_push;; @@ -120,4 +128,5 @@ case $option in 9) undo_git_merge "unpushed";; 10) undo_git_merge "pushed";; 11) recover_lost_stash;; + 12) undo_git_stash_apply;; esac