From aa3c295ee837ad12bcf43ad41872a179088f50b8 Mon Sep 17 00:00:00 2001 From: Bhupesh-V Date: Fri, 30 Apr 2021 19:53:06 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A9=20use=20better=20version=20to=20re?= =?UTF-8?q?store=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CONTRIBUTING.md | 3 ++- README.md | 9 +++++---- ugit | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1fbdd34..421b079 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Contributing to sample-project +# Contributing to `ugit` :+1::tada: First off, thanks for taking the time to contribute! :tada::+1: @@ -7,3 +7,4 @@ Make sure you follow below guidelines before contributing. 1. Raise an issue before sending any PR. 2. Make you changes to `feature` branch. 3. See if there is already an open PR for the same issue. + diff --git a/README.md b/README.md index b1f1275..f34c2f3 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ ## What's in the box -`ugit` supports undoing following operations, some are a WIP. If you know of any operation that can be undone and is not in the list, make sure to send a quick PR 💛️ +`ugit` supports undoing following operations, some are a WIP. If you know of any other operations that can be undone and is not in the list, make sure to send a quick PR 💛️ - [x] Undo `git commit` - [x] Undo `git add` @@ -48,9 +48,10 @@ **ugit** dependencies: -1. `Bash>=3` -2. GNU utils like `awk`, `grep`, `tput` etc -3. [fzf](https://github.com/junegunn/fzf) +- `Bash`>=3 +- GNU utils like `awk`, `grep`, `tput` etc +- [fzf](https://github.com/junegunn/fzf) + 1. Install the script using `wget` ```bash diff --git a/ugit b/ugit index 7908ad7..6e081e5 100755 --- a/ugit +++ b/ugit @@ -194,12 +194,13 @@ undo_file_delete() { restore_file() { FILE=$(git ls-files | fzf --ansi --height 20% --reverse --header="Choose file to restore" | awk '{print $1}') COMMIT=$(git log --oneline "$FILE" | fzf --ansi --height 80% --reverse --prompt="Choose commit to restore file to" --header="Use ctrl-j/ctrl-k to navigate file preview. ctrl+space to toggle preview" --preview "echo {} | cut -d' ' -f1 | xargs -I{} git show {}:$FILE" --bind 'j:down,k:up,ctrl-j:preview-down,ctrl-k:preview-up,ctrl-space:toggle-preview' --preview-window down:60%) + COMMIT=$(printf "%s" "$COMMIT" | awk '{print $1}') if ! git diff -s --quiet "$FILE"; then # check if any local changes printf "%s\n" "$FILE seems to be modified. Please either commit or discard those changes." exit 0 - elif git reset "$COMMIT" "$FILE"; then + elif git restore --source="$COMMIT" "$FILE"; then printf "%s\n" "$FILE restored to version at $COMMIT" fi }