Compare commits

..

No commits in common. "master" and "v5.7" have entirely different histories.
master ... v5.7

4 changed files with 36 additions and 163 deletions

View file

@ -118,24 +118,6 @@
"contributions": [
"code"
]
},
{
"login": "T-Joseph-Kim",
"name": "Taebok Joseph Kim",
"avatar_url": "https://avatars.githubusercontent.com/u/116681578?v=4",
"profile": "https://github.com/T-Joseph-Kim",
"contributions": [
"code"
]
},
{
"login": "luxxmr",
"name": "luxxmr",
"avatar_url": "https://avatars.githubusercontent.com/u/185298948?v=4",
"profile": "https://github.com/luxxmr",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 7,
@ -144,6 +126,5 @@
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true,
"commitConvention": "angular",
"commitType": "docs"
"commitConvention": "angular"
}

View file

@ -1,71 +0,0 @@
FROM alpine:3.18 as ugit-ops
RUN apk add --no-cache \
bash \
coreutils \
git \
ncurses \
curl
# Download fzf binary from GitHub, pin to 0.46.0, ugit requires minimum 0.21.0
RUN curl -L -o fzf.tar.gz https://github.com/junegunn/fzf/releases/download/0.46.0/fzf-0.46.0-linux_amd64.tar.gz && \
tar -xzf fzf.tar.gz && \
mv fzf /usr/bin/
# Copy only the ugit script into the container at /app
COPY ugit .
# Set permissions and move the script to path
RUN chmod +x ugit && mv ugit /usr/bin/
# Second stage: Copy only necessary binaries and their dependencies
FROM scratch
LABEL description="Undo your last oopsie in git with ugit"
LABEL maintainer="Bhupesh Varshney <varshneybhupesh@gmail.com>"
COPY --from=ugit-ops /usr/bin/ugit /bin/
COPY --from=ugit-ops /usr/bin/git /usr/bin/
COPY --from=ugit-ops /usr/bin/fzf /usr/bin/
COPY --from=ugit-ops /usr/bin/tput /usr/bin/
COPY --from=ugit-ops /usr/bin/nl /usr/bin/
COPY --from=ugit-ops /usr/bin/awk /usr/bin/
COPY --from=ugit-ops /usr/bin/xargs /usr/bin/
COPY --from=ugit-ops /usr/bin/cut /usr/bin/
COPY --from=ugit-ops /usr/bin/tr /usr/bin/
COPY --from=ugit-ops /bin/bash /bin/
COPY --from=ugit-ops /bin/grep /bin/
# copy lib files
# COPY --from=ugit-ops /usr/lib/libncursesw* /usr/lib/
COPY --from=ugit-ops /usr/lib/libncursesw.so.6 /usr/lib/
# COPY --from=ugit-ops /usr/lib/libpcre* /usr/lib/
COPY --from=ugit-ops /usr/lib/libpcre2-8.so.0 /usr/lib/
# COPY --from=ugit-ops /usr/lib/libreadline* /usr/lib/
COPY --from=ugit-ops /usr/lib/libreadline.so.8 /usr/lib/
COPY --from=ugit-ops /lib/libacl.so.1 /lib/
COPY --from=ugit-ops /lib/libattr.so.1 /lib/
COPY --from=ugit-ops /lib/libc.musl-* /lib/
COPY --from=ugit-ops /lib/ld-musl-* /lib/
COPY --from=ugit-ops /lib/libutmps.so.0.1 /lib/
COPY --from=ugit-ops /lib/libskarnet.so.2.13 /lib/
COPY --from=ugit-ops /lib/libz.so.1 /lib/
# copy terminfo database
COPY --from=ugit-ops /etc/terminfo/x/xterm-256color /usr/share/terminfo/x/
# Gib me all the colors
ENV TERM=xterm-256color
# Let fzf know our deault shell
ENV SHELL=/bin/bash
# Let ugit know we are running in docker
ENV UGIT_RUNNING_IN_DOCKER=true
WORKDIR /app
# Run ugit when the container launches
ENTRYPOINT ["/bin/bash", "/bin/ugit"]

View file

@ -5,8 +5,8 @@
<a href="https://github.com/Bhupesh-V/ugit/actions/workflows/build.yml">
<img alt="build ugit" src="https://github.com/Bhupesh-V/ugit/actions/workflows/build.yml/badge.svg">
</a>
<a href="https://hub.docker.com/r/bhupeshimself/ugit">
<img alt="Docker pulls" src="https://img.shields.io/docker/pulls/bhupeshimself/ugit?logo=docker" target="_blank" />
<a href="https://github.com/Bhupesh-V/ugit/blob/master/LICENSE">
<img alt="License: MIT" src="https://img.shields.io/github/license/Bhupesh-V/ugit" target="_blank" />
</a>
<img alt="total downloads (github + brew)" src="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/Bhupesh-V/6b7b8e8576bc1ca237bffd9a344672ab/raw/ugit-downloads.json">
<a href="">
@ -39,16 +39,16 @@ https://user-images.githubusercontent.com/34342551/121651071-d9fd1580-cab7-11eb-
## Why use `ugit`?
- You accidentally ran a `git` command you wish to 'undo'.
- You ran an accidental `git` command you wish to 'undo'.
- You want to save time by not searching for _how to undo ..._
- Your focus is on the problems at hand and not on Git (avoid context switching)
- Your focus is on problems at hand and not on Git (avoid context switching)
- Because `ugit` is precise & uber cool !
### [Motivations behind writing ugit 🙇‍♂️️](https://bhupesh-v.github.io/undo-your-last-git-mistake-with-ugit)
## What's in the box?
## What's in the box ?
`ugit`/`git-undo` supports undoing the following operations, some are a WIP. If you know of any other operations that can be undone and are not in the list, make sure to raise an issue or make a quick PR 💛️
`ugit`/`git-undo` 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 raise an issue or make a quick PR 💛️
- [x] Undo `git commit`
- [x] Undo `git add`
@ -67,7 +67,7 @@ https://user-images.githubusercontent.com/34342551/121651071-d9fd1580-cab7-11eb-
- [ ] Undo `git rebase`
- [ ] Undo `git worktree remove` (recover deleted work-tree)
Contribute to the project by helping me with the above-mentioned tasks.
Contribute to the project by helping me with the above mentioned tasks.
If you have any other ideas/suggestions, do send them across. [**Hop in to ugit discussions 💬️**](https://github.com/Bhupesh-V/ugit/discussions/7)
@ -83,18 +83,11 @@ If you have any other ideas/suggestions, do send them across. [**Hop in to ugit
## Community
- Alexander Alemayhu made a YouTube tutorial on [Undoing Your Last Git Commit with Ugit](https://www.youtube.com/watch?v=nUnCgKb4tSc)
- Alexander Alemayhu made a youtube tutorial on [Undoing Your Last Git Commit with Ugit](https://www.youtube.com/watch?v=nUnCgKb4tSc)
## Installation
[Try `ugit` via Docker](https://hub.docker.com/r/bhupeshimself/ugit):
```bash
docker pull bhupeshimself/ugit
docker run --rm -it -v $(pwd):/app bhupeshimself/ugit
```
### Prerequisites
**ugit** dependencies:
@ -104,10 +97,6 @@ docker run --rm -it -v $(pwd):/app bhupeshimself/ugit
- [**fzf**](https://github.com/junegunn/fzf) >= `0.21.0` - [Installation guide](https://github.com/junegunn/fzf#installation)
- GNU utils like `awk`, `grep`, `tput` etc
<br>
[![Packaging status](https://repology.org/badge/vertical-allrepos/ugit.svg)](https://repology.org/project/ugit/versions)
### Linux
@ -115,7 +104,7 @@ docker run --rm -it -v $(pwd):/app bhupeshimself/ugit
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Bhupesh-V/ugit/master/install)"
```
Arch Linux users can install [**ugit via AUR**](https://aur.archlinux.org/packages/ugit).
Or Arch Linux users can install [**ugit via AUR**](https://aur.archlinux.org/packages/ugit).
### Mac
@ -125,7 +114,7 @@ brew install ugit
### Windows
To use ugit on Windows you need to install:
To use ugit on windows you need to install:
1. Git Bash<br>
Git bash comes with git (if you have installed it on your machine then no need). To install git (preferably with scoop):
@ -192,15 +181,6 @@ If you're using [oh-my-zsh](github.com/robbyrussell/oh-my-zsh):
`source ~/.zshrc`
### Note on `git-undo` Command Conflict
If you have both `ugit` and `git-extras` (https://github.com/tj/git-extras) installed, be aware that both provide a `git-undo` command. This can lead to conflicts, as only one version of the command will be accessible at a time. To resolve this:
- **Using Homebrew**: Homebrew will notify you of the conflict during installation. You can choose to unlink the conflicting formula or use the --overwrite flag to force the link as follows:
`brew link --overwrite ugit`
- **Manual Installation**: Ensure that the `git-undo` command from the desired package is prioritized in your system's PATH.
## Please read ⚠️
@ -208,14 +188,14 @@ If you have both `ugit` and `git-extras` (https://github.com/tj/git-extras) inst
Git comes with a garbage collector ([in case you didn't know](https://git-scm.com/docs/git-gc)) therefore undoing some commands will become impossible if the entries are deleted from the reflog.
One way to prevent this is to increase default time limits before the reflog entries expire.
Add these configurations in your global `.gitconfig` file:
Add these configuration in your global `.gitconfig` file:
```gitconfig
[gc]
# default 90 days
reflogExpire = 200
```
Used to set how long records in a branch reflog should be preserved.
Used to set how long records in a branches reflog should be preserved.
```gitconfig
[gc]
@ -271,8 +251,6 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/RohitSingh107"><img src="https://avatars.githubusercontent.com/u/64142943?v=4?s=100" width="100px;" alt="RohitSingh107"/><br /><sub><b>RohitSingh107</b></sub></a><br /><a href="#platform-RohitSingh107" title="Packaging/porting to new platform">📦</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Theotime812"><img src="https://avatars.githubusercontent.com/u/45947878?v=4?s=100" width="100px;" alt="Théotime Maillarbaux"/><br /><sub><b>Théotime Maillarbaux</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=Theotime812" title="Code">💻</a> <a href="https://github.com/Bhupesh-V/ugit/issues?q=author%3ATheotime812" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/dr41d45"><img src="https://avatars.githubusercontent.com/u/47773787?v=4?s=100" width="100px;" alt="dr41d45"/><br /><sub><b>dr41d45</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=dr41d45" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/T-Joseph-Kim"><img src="https://avatars.githubusercontent.com/u/116681578?v=4?s=100" width="100px;" alt="Taebok Joseph Kim"/><br /><sub><b>Taebok Joseph Kim</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=T-Joseph-Kim" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/luxxmr"><img src="https://avatars.githubusercontent.com/u/185298948?v=4?s=100" width="100px;" alt="luxxmr"/><br /><sub><b>luxxmr</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=luxxmr" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>

59
ugit
View file

@ -7,7 +7,7 @@ set -uo pipefail;
SCRIPT_NAME="$0"
SCRIPT_URL="https://github.com/Bhupesh-V/ugit/releases/latest/download/ugit"
TMP_FILE="/tmp/ugit.sh"
VERSION="5.9"
VERSION="5.7"
pointer=""
BOLD_ORG_FG=$(tput bold)$(tput setaf 208)
@ -246,21 +246,12 @@ recover_deleted_tag() {
undo_file_delete() {
if [[ "$1" = "uncommited" ]]; then
# user didn't commit the file deletion
readarray -t DELETED_FILES < <(
git ls-files -d |
fzf --ansi --height 20% --reverse --header="Choose deleted files to recover" --multi |
awk '{print $1}'
)
if [ ${#DELETED_FILES[@]} -eq 0 ]; then
DELETED_FILE=$(git ls-files -d | fzf --ansi --height 20% --reverse --header="Choose deleted file to recover" | awk '{print $1}')
if git checkout HEAD "$DELETED_FILE"; then
printf "%s\n" "${BOLD}$DELETED_FILE${RESET} Successfully Recovered 👍️"
exit 0
fi
if git checkout HEAD -- "${DELETED_FILES[@]}"; then
printf "%s\n" "${BOLD}${DELETED_FILES[*]}${RESET}"
printf "%s\n" "Successfully Recovered ${#DELETED_FILES[@]} file(s)"
else
perror "Unable to recover ${BOLD}${DELETED_FILES[*]}${RESET}"
perror "Unable to recover ${BOLD}$DELETED_FILE${RESET}"
fi
elif [[ "$1" = "commited" ]]; then
read -p "Enter complete filename: " -r FILENAME
@ -432,17 +423,22 @@ show_version() {
}
print_help() {
printf "Usage: %s [-h] [-v] [-u] [-g]\n" "ugit"
printf "ugit helps you undo git commands without much effort\n"
printf "Just run 'ugit' and search for what you want to undo\n\n"
printf "Available options:\n"
printf " -h, --help Print this help and exit\n"
printf " -v, --version Print current ugit version\n"
printf " -u, --update Update ugit\n"
printf " -g, --guide Open the ugit undo text guide\n\n"
printf "Contact 📬️: %s for assistance\n" "$(tput bold)varshneybhupesh@gmail.com${RESET}"
printf "Read the guide: %s\n" "https://til.bhupesh.me/git/how-to-undo-anything-in-git"
printf "Please give us a ⭐ if you liked ugit %s\n" "${BOLD_ORG_FG}https://github.com/Bhupesh-V/ugit${RESET}"
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-u] [-g]
ugit helps you undo git commands without much effort
Just run 'ugit' and search for what you want to undo
Available options:
-h, --help Print this help and exit
-v, --version Print current ugit version
-u, --update Update ugit
-g, --guide Open ugit undo text guide
EOF
printf "\n%s\n" "Contact 📬️: $(tput bold)varshneybhupesh@gmail.com${RESET} for assistance"
printf "%s\n" "Read the guide: https://bhupesh.gitbook.io/notes/git/how-to-undo-anything-in-git"
printf "\n%s\n" "Please give us ⭐ a if you liked ugit ${BOLD_ORG_FG}https://github.com/Bhupesh-V/ugit${RESET}"
}
get_changelog() {
@ -453,12 +449,6 @@ get_changelog() {
}
ugit_update() {
if [ -n "${UGIT_RUNNING_IN_DOCKER-}" ] && [ "$UGIT_RUNNING_IN_DOCKER" = true ]; then
printf "%s\n\n" "You are running version ${VERSION} of ugit via Docker. Please pull the latest docker image to update."
printf "\t%s\n" "${BOLD_ORG_FG}docker pull bhupeshimself/ugit${RESET}"
return
fi
printf "%s\n" "Checking for updates ..."
curl -s -L "$SCRIPT_URL" > "$TMP_FILE"
NEW_VER=$(grep "^VERSION" "$TMP_FILE" | awk -F'[="]' '{print $3}')
@ -478,12 +468,7 @@ ugit_update() {
}
open_guide() {
GUIDE="https://til.bhupesh.me/git/how-to-undo-anything-in-git"
if [ -n "${UGIT_RUNNING_IN_DOCKER-}" ] && [ "$UGIT_RUNNING_IN_DOCKER" = true ]; then
printf "%s\n" "You can find how ugit does its magic at: ${BOLD_ORG_FG}${GUIDE}${RESET}"
return
fi
GUIDE="https://bhupesh.gitbook.io/notes/git/how-to-undo-anything-in-git"
case "$OSTYPE" in
darwin*)