Skip to content

Commit

Permalink
💩 use better version to restore files
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhupesh-V committed Apr 30, 2021
1 parent f8cf84d commit aa3c295
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to sample-project
# Contributing to `ugit`

:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:

Expand All @@ -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.

9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion ugit
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit aa3c295

Please sign in to comment.