Compare commits

..

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

7 changed files with 82 additions and 414 deletions

View file

@ -63,79 +63,6 @@
"contributions": [
"code"
]
},
{
"login": "zora89",
"name": "Zorawar Purohit",
"avatar_url": "https://avatars.githubusercontent.com/u/42845567?v=4",
"profile": "https://www.zorawarpurohit.com",
"contributions": [
"doc"
]
},
{
"login": "nalin-singh",
"name": "Nalin Singh",
"avatar_url": "https://avatars.githubusercontent.com/u/38408670?v=4",
"profile": "https://craftic.webflow.io",
"contributions": [
"code"
]
},
{
"login": "vinayaknayar",
"name": "vinayaknayar",
"avatar_url": "https://avatars.githubusercontent.com/u/98237998?v=4",
"profile": "https://github.com/vinayaknayar",
"contributions": [
"doc"
]
},
{
"login": "RohitSingh107",
"name": "RohitSingh107",
"avatar_url": "https://avatars.githubusercontent.com/u/64142943?v=4",
"profile": "https://github.com/RohitSingh107",
"contributions": [
"platform"
]
},
{
"login": "Theotime812",
"name": "Théotime Maillarbaux",
"avatar_url": "https://avatars.githubusercontent.com/u/45947878?v=4",
"profile": "https://github.com/Theotime812",
"contributions": [
"code",
"bug"
]
},
{
"login": "dr41d45",
"name": "dr41d45",
"avatar_url": "https://avatars.githubusercontent.com/u/47773787?v=4",
"profile": "https://github.com/dr41d45",
"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,
@ -143,7 +70,5 @@
"projectOwner": "Bhupesh-V",
"repoType": "github",
"repoHost": "https://github.com",
"skipCi": true,
"commitConvention": "angular",
"commitType": "docs"
"skipCi": true
}

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"]

142
README.md
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="">
@ -37,18 +37,18 @@ https://user-images.githubusercontent.com/34342551/121651071-d9fd1580-cab7-11eb-
</details></h2>
## Why use `ugit`?
- You accidentally ran a `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)
## Why `ugit`
- You ran an accidental `git` command you didn't want to.
- You don't want to waste your time searching on _how to undo ..._
- Because you want to focus on problems at hand and not on Git (You don't like context switching)
- Because `ugit` is 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 send a quick PR 💛️
- [x] Undo `git commit`
- [x] Undo `git add`
@ -63,19 +63,18 @@ https://user-images.githubusercontent.com/34342551/121651071-d9fd1580-cab7-11eb-
- [x] Undo (Restore) a file to a previous version
- [x] Undo `git merge`
- [x] Undo `git cherry-pick`
- [x] Undo `git tag`
- [ ] Undo `git tag` (rename a tag)
- [ ] Undo `git rebase`
- [ ] Undo `git worktree remove` (recover deleted work-tree)
Contribute to the project by helping me with the above-mentioned tasks.
Help me finish above tasks by contributing?
If you have any other ideas/suggestions, do send them across. [**Hop in to ugit discussions 💬️**](https://github.com/Bhupesh-V/ugit/discussions/7)
Have any other ideas/suggestions? [**Hop in to ugit discussions 💬️**](https://github.com/Bhupesh-V/ugit/discussions/7)
## News
| When | What |
|:--------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 29 Oct, 2022 | ugit crossed 1k stars |
| 02 June, 2022 | [console.dev](https://console.dev/tools/) featured [ugit](https://twitter.com/bhupeshimself/status/1532714651842396161) |
| 18 May, 2022 | I gave a talk about the git tooling ecosystem & `git undo` in [Undo git, say whaat! - **GitHub India Constellation**, May 2022](https://youtu.be/jpR9BMFmh4Y?t=15240) |
| 12 May, 2021 | The [guide was **tweeted by GitHub**](https://twitter.com/github/status/1392207961355862018?s=20) (I was logging my research process there while building ugit) |
@ -83,18 +82,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,54 +96,9 @@ 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>
### Installation
[![Packaging status](https://repology.org/badge/vertical-allrepos/ugit.svg)](https://repology.org/project/ugit/versions)
### Linux
```bash
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).
### Mac
```bash
brew install ugit
```
### Windows
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):
```
scoop install git
```
2. FZF
```
scoop install fzf
```
Alternatively, with Chocolatey:
```
choco install fzf
```
3. To use bash in terminal change your directory to `**git\2.35.3.windows.1\bin\bash**` accordingly.
4. Then either clone the repo,
```bash
git clone https://github.com/Bhupesh-V/ugit.git
```
or get it using curl:
```bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Bhupesh-V/ugit/master/install)"
```
### Fig
#### Fig
[Fig](https://fig.io) adds apps, shortcuts, and autocomplete to your existing terminal.
@ -159,6 +106,24 @@ Install `ugit` in just one click.
<a href="https://fig.io/plugins/other/ugit_Bhupesh-V" target="_blank"><img src="https://fig.io/badges/install-with-fig.svg" /></a>
#### Linux
```bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Bhupesh-V/ugit/master/install)"
```
Or Arch Linux users can install [**ugit via AUR**](https://aur.archlinux.org/packages/ugit).
#### Mac
```bash
brew install ugit
```
#### Windows
Using ugit on windows is still in experimental phases. You can use the new windows terminal + git bash to run ugit. Please read [this thread for more info](https://github.com/Bhupesh-V/ugit/issues/20#issuecomment-1048234725)
### ZSH Frameworks
@ -192,15 +157,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 +164,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]
@ -255,26 +211,14 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/sharan-aithal"><img src="https://avatars.githubusercontent.com/u/32029982?v=4?s=100" width="100px;" alt="Sharan Aithal"/><br /><sub><b>Sharan Aithal</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=sharan-aithal" title="Code">💻</a> <a href="https://github.com/Bhupesh-V/ugit/commits?author=sharan-aithal" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://tabulate.tech"><img src="https://avatars.githubusercontent.com/u/58576759?v=4?s=100" width="100px;" alt="Tabulate"/><br /><sub><b>Tabulate</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=TabulateJarl8" title="Code">💻</a> <a href="#platform-TabulateJarl8" title="Packaging/porting to new platform">📦</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://unixorn.github.io"><img src="https://avatars.githubusercontent.com/u/23920?v=4?s=100" width="100px;" alt="Joe Block"/><br /><sub><b>Joe Block</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=unixorn" title="Code">💻</a> <a href="https://github.com/Bhupesh-V/ugit/commits?author=unixorn" title="Documentation">📖</a> <a href="#plugin-unixorn" title="Plugin/utility libraries">🔌</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://thecesrom.dev/"><img src="https://avatars.githubusercontent.com/u/19418023?v=4?s=100" width="100px;" alt="César Román"/><br /><sub><b>César Román</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=thecesrom" title="Code">💻</a> <a href="https://github.com/Bhupesh-V/ugit/issues?q=author%3Athecesrom" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ibayramli2001"><img src="https://avatars.githubusercontent.com/u/43158991?v=4?s=100" width="100px;" alt="Ilkin Bayramli"/><br /><sub><b>Ilkin Bayramli</b></sub></a><br /><a href="#platform-ibayramli2001" title="Packaging/porting to new platform">📦</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/kopalchakravarty"><img src="https://avatars.githubusercontent.com/u/31576619?v=4?s=100" width="100px;" alt="Kopal Chakravarty"/><br /><sub><b>Kopal Chakravarty</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=kopalchakravarty" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://www.zorawarpurohit.com"><img src="https://avatars.githubusercontent.com/u/42845567?v=4?s=100" width="100px;" alt="Zorawar Purohit"/><br /><sub><b>Zorawar Purohit</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=zora89" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://craftic.webflow.io"><img src="https://avatars.githubusercontent.com/u/38408670?v=4?s=100" width="100px;" alt="Nalin Singh"/><br /><sub><b>Nalin Singh</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=nalin-singh" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/vinayaknayar"><img src="https://avatars.githubusercontent.com/u/98237998?v=4?s=100" width="100px;" alt="vinayaknayar"/><br /><sub><b>vinayaknayar</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=vinayaknayar" title="Documentation">📖</a></td>
<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>
<tr>
<td align="center"><a href="https://github.com/sharan-aithal"><img src="https://avatars.githubusercontent.com/u/32029982?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Sharan Aithal</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=sharan-aithal" title="Code">💻</a> <a href="https://github.com/Bhupesh-V/ugit/commits?author=sharan-aithal" title="Documentation">📖</a></td>
<td align="center"><a href="https://tabulate.tech"><img src="https://avatars.githubusercontent.com/u/58576759?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tabulate</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=TabulateJarl8" title="Code">💻</a> <a href="#platform-TabulateJarl8" title="Packaging/porting to new platform">📦</a></td>
<td align="center"><a href="http://unixorn.github.io"><img src="https://avatars.githubusercontent.com/u/23920?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Joe Block</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=unixorn" title="Code">💻</a> <a href="https://github.com/Bhupesh-V/ugit/commits?author=unixorn" title="Documentation">📖</a> <a href="#plugin-unixorn" title="Plugin/utility libraries">🔌</a></td>
<td align="center"><a href="https://thecesrom.dev/"><img src="https://avatars.githubusercontent.com/u/19418023?v=4?s=100" width="100px;" alt=""/><br /><sub><b>César Román</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=thecesrom" title="Code">💻</a> <a href="https://github.com/Bhupesh-V/ugit/issues?q=author%3Athecesrom" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://github.com/ibayramli2001"><img src="https://avatars.githubusercontent.com/u/43158991?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ilkin Bayramli</b></sub></a><br /><a href="#platform-ibayramli2001" title="Packaging/porting to new platform">📦</a></td>
<td align="center"><a href="https://github.com/kopalchakravarty"><img src="https://avatars.githubusercontent.com/u/31576619?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kopal Chakravarty</b></sub></a><br /><a href="https://github.com/Bhupesh-V/ugit/commits?author=kopalchakravarty" title="Code">💻</a></td>
</tr>
</table>
<!-- markdownlint-restore -->

154
ugit
View file

@ -7,9 +7,8 @@ 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.2"
pointer=""
BOLD_ORG_FG=$(tput bold)$(tput setaf 208)
BOLD=$(tput bold)
RESET=$(tput sgr0)
@ -35,14 +34,10 @@ display_menu() {
printf "%s\n" "Undo ${BOLD_ORG_FG}git cherry-pick${RESET}"
printf "%s\n" "Undo all current uncommited changes"
printf "%s\n" "Undo ${BOLD_ORG_FG}git tag${RESET}"
printf "%s\n" "Undo ${BOLD_ORG_FG}git rm${RESET}"
}
perror() {
printf "%s\n" "$(tput bold)$(tput setaf 196)ugit error${RESET}: $1"
printf "%s\n" "If you think this is a Ugit bug, please follow this link to report it:"
printf "%s\n" "${BOLD_ORG_FG}https://github.com/Bhupesh-V/ugit/issues/new?template=bug-report.yml${RESET}"
exit
}
undo_git_commit() {
@ -65,23 +60,14 @@ undo_git_commit() {
# This will not delete the files from your working directory
if [[ "$last_commit" == "$initial_commit" ]]; then
if git update-ref -d HEAD && git rm --cached -rf . > /dev/null 2>&1; then
printf "%s\n" "Initial commit: $initial_commit successfully undone. Commit state is clean."
else
perror "Error: Failed to revert initial commit"
exit
printf "%s\nInitial commit: $initial_commit successfully undone. Commit state is clean."
fi
elif git reset HEAD~; then
printf "%s\n" "Commit: $last_commit successfully undone"
else
perror "Failed to revert commit $last_commit"
exit
fi
elif git revert "$commit"; then
printf "%s\n" "Commit: $commit successfully reverted. Check ${BOLD_ORG_FG}git status${RESET}"
else
perror "Error: unable to perfom operation"
fi
}
do_git_reset() {
@ -91,7 +77,7 @@ do_git_reset() {
# check if working tree is clean or not
[[ $(git status --porcelain 2>/dev/null) != "" ]] && read -p "You have uncommited changes, still proceed? [Y/n]: " -n 1 -r USER_INPUT
USER_INPUT=${USER_INPUT:-Y}
[[ "$USER_INPUT" == Y ]] && git reset --hard "$last_good_state" || perror "Error: unable to perform reset operation"
[[ "$USER_INPUT" == Y ]] && git reset --hard "$last_good_state"
}
undo_git_add() {
@ -103,8 +89,6 @@ undo_git_add() {
if [[ ${#choices[@]} -gt 0 ]] && git restore --staged "${choices[@]}"; then
printf "%s\n" "Done 👍️"
else
perror "Error: unable to perform operation"
fi
}
@ -113,8 +97,8 @@ change_commit_message() {
printf "%s" "Enter New Commit Message (Ctrl+d to save):"
msg=$(</dev/stdin)
echo
[[ "$msg" != "" ]] && git commit --amend -m "$msg" && printf "%s\n" "Remember to run ${BOLD_ORG_FG}git push -f <remoteName> <branchName>${RESET} if this was a pushed commit" \
|| perror "Empty Commit string!"
[[ "$msg" != "" ]] && git commit --amend -m "$msg" || perror "Empty Commit string!"
printf "%s\n" "Remember to run ${BOLD_ORG_FG}git push -f <remoteName> <branchName>${RESET} if this was a pushed commit"
}
undo_git_push() {
@ -122,8 +106,6 @@ undo_git_push() {
if git revert "$commit"; then
printf "%s\n" "Commit: $commit successfully reverted."
printf "%s\n" "Make sure to run ${BOLD_ORG_FG}git push${RESET} now!"
else
perror "Error: unable to perform operation"
fi
}
@ -136,7 +118,7 @@ undo_branch_delete() {
if [ -n "$BRANCH_NAME" ] && git checkout -b "$BRANCH_NAME" "$last_branch_commit"; then
printf "%s\n" "Branch $BRANCH_NAME successfully recovered 👍️"
else
perror "Failed to recover branch $BRANCH_NAME"
perror "Error: unable to perform operation"
fi
}
@ -144,8 +126,6 @@ undo_git_reset() {
LAST_GOOD_STATE=$(git reflog | fzf --ansi --height 20% --reverse --multi --header="Choose last known good commit" | awk '{print $1}')
if [[ -n "$LAST_GOOD_STATE" ]] && git reset "$LAST_GOOD_STATE"; then
printf "%s\n" "Reset to $LAST_GOOD_STATE 👍️"
else
perror "Unable to reset state"
fi
}
@ -163,15 +143,7 @@ undo_git_merge() {
[[ $(git status --porcelain 2>/dev/null) != "" ]] && read -p "You have uncommited changes, still proceed? [Y/n]: " -n 1 -r USER_INPUT
USER_INPUT=${USER_INPUT:-Y}
# ref: ORIG_HEAD points to the original commit from before the merge
if [[ "$USER_INPUT" == Y ]]; then
if git reset --merge ORIG_HEAD; then
printf "Operation completed successfully"
else
perror "Unable to revert merge commit"
fi
else
exit
fi
[[ "$USER_INPUT" == Y ]] && git reset --merge ORIG_HEAD || exit 0
# [[ "$USER_INPUT" == Y ]] && git reset --merge "$last_good_state" || exit 0
else
default_branch=$(git remote show origin | awk '/HEAD/ {print $3}')
@ -180,27 +152,20 @@ undo_git_merge() {
commit=$(git log --oneline | fzf --ansi --height 10% --reverse --header="Choose the merge commit" | awk '{print $1}')
if git revert -m 1 "$commit"; then
printf "%s\n" "Merge ($commit) successfully reverted 👍️"
else perror "Unable to revert merge commit"
fi
fi
}
recover_lost_stash() {
LOST_STASH=$(git fsck --no-progress --unreachable |
awk '/commit/ {print $3}' |
xargs git log --color --oneline --merges --no-walk
LOST_STASH=$(git fsck --no-progress --unreachable | \
awk '/commit/ {print $3}' | \
xargs git log --color --oneline --merges --no-walk | \
fzf --ansi --height 20% --reverse --header="Choose commit associated with stash" | awk '{print $1}'
)
if [ -z "$LOST_STASH" ]; then
printf "%s\n" "No unreachable commits found. Exiting..."
exit
fi
[[ "$LOST_STASH" ]] && read -p "Enter Stash Description: " -r STASH_MSG || exit
STASH=$(echo "$LOST_STASH" | fzf --ansi --height 20% --reverse --header="Choose commit associated with stash" | awk '{print $1}')
read -p "Enter Stash Description: " -r STASH_MSG
if git update-ref refs/stash "$STASH" --create-reflog -m "$STASH_MSG"; then
if git update-ref refs/stash "$LOST_STASH" --create-reflog -m "$STASH_MSG"; then
printf "%s\n" "Stash Successfully Recovered 👍️"
else
perror "Unable to recover stash"
@ -246,22 +211,11 @@ 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}"
fi
elif [[ "$1" = "commited" ]]; then
read -p "Enter complete filename: " -r FILENAME
COMMIT=$(git log --color --diff-filter=D --oneline | fzf --ansi --height 50% \
@ -275,8 +229,6 @@ undo_file_delete() {
if git checkout "$COMMIT"~1 -- "$FILENAME"; then
printf "%s\n" "${BOLD}$FILENAME${RESET} Successfully Recovered 👍️"
else
perror "Unable to recover ${BOLD}$FILENAME${RESET}"
fi
fi
}
@ -302,8 +254,6 @@ restore_file() {
exit 0
elif [[ "$COMMIT" != "" && "$FILE" != "" ]] && git restore --source="$COMMIT" "$FILE"; then
printf "%s\n" "$FILE restored to version at ${BOLD}$COMMIT${RESET}"
else
perror "Error: unable to perform operation"
fi
}
@ -321,8 +271,6 @@ undo_all() {
# printf "%s\n" "Note: Stashing untracked files might take some time, hold on"
printf "%s\n" "Cleared all changes 👍️"
printf "%s\n" "Run ${BOLD_ORG_FG}git stash apply${RESET} to redo changes or ${BOLD_ORG_FG}git stash drop${RESET} to remove them"
else
perror "Error: unable to perform operation"
fi
}
@ -334,7 +282,7 @@ undo_git_tag() {
perror "Unable to fetch tags from remote.Please check repository access."
exit
fi
tag=$(git tag --sort=v:refname | fzf --ansi --height 80% \
tag=$(git tag | fzf --ansi --height 80% \
--reverse --multi --header="Choose a tag to remove" \
--preview "echo {} | cut -d' ' -f1 | xargs -I{} git show --color --pretty=format:%b {}" \
--bind 'j:down,k:up,ctrl-j:preview-down,ctrl-k:preview-up,ctrl-space:toggle-preview' --preview-window right:60% )
@ -358,20 +306,6 @@ undo_git_tag() {
fi
}
undo_git_rm(){
# Find all the deleted files from git history
filepath=$(git log --diff-filter=D --summary | grep delete | nl -n ln | fzf --header="Choose the file to restore" --height 50% --ansi --reverse "$pointer" --cycle | awk '{print $5}')
# Find the commit hash value of the selected filepath
commit=$(git log -- "$filepath"| awk 'NR==1{print $2}')
# Restore the file
if git checkout "$commit"^ "$filepath"; then
printf "%s\n" "File $filepath restored successfully."
else
perror "Unable to restore Fie $filepath"
fi
}
ugit_menu() {
case $option in
1) undo_git_commit;;
@ -394,7 +328,6 @@ ugit_menu() {
18) undo_git_commit;;
19) undo_all;;
20) undo_git_tag;;
21) undo_git_rm;;
esac
}
@ -419,12 +352,6 @@ check_deps() {
for dep in "${deps[@]}"; do
installed "${dep}" || die "Missing dependency: '${dep}'"
done
# if version of fzf < 0.21, do not use --pointer
fzf_version=$(fzf --version | cut -d "." -f 1,2 | tr -d '.()[:alpha:]')
if test "$fzf_version" -ge 021; then
pointer="--pointer=👉"
fi
}
show_version() {
@ -432,33 +359,33 @@ 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() {
# get changelog/release notes for the most recent release
REMOTE_REPO="Bhupesh-V/ugit"
CHANGELOG=$(curl -s -L https://api.github.com/repos/$REMOTE_REPO/releases | awk -F=":" '/html_url/ {print $1;exit}' | cut -d ':' -f 2,3 | tr -d "\", ")
printf "Read Full Changelog: %s\n" "${BOLD}${CHANGELOG}${RESET}"
CHANGELOG=$(curl -s -L https://api.github.com/repos/$REMOTE_REPO/releases | awk -F=":" '/body/ {print $1;exit}' | cut -d ':' -f 2 | tr -d "\"")
printf "%s\n" "${BOLD}Changelog:${RESET}"
echo -e "${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 +405,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*)
@ -541,7 +463,7 @@ main() {
check_deps
init_test
header
option=$(display_menu | nl -n ln | fzf --header="Don't worry we all mess up sometimes" --height 50% --ansi --reverse "$pointer" --cycle | awk '{print $1}')
option=$(display_menu | nl -n ln | fzf --header="Don't worry we all mess up sometimes" --height 50% --ansi --reverse --pointer='👉' --cycle | awk '{print $1}')
ugit_menu
fi
}

View file

@ -1,2 +0,0 @@
.flatpak-builder
build-dir

View file

@ -1,45 +0,0 @@
app-id: org.Bhupesh-V.ugit
runtime: org.freedesktop.Platform
runtime-version: '21.08'
sdk: org.freedesktop.Sdk
command: ugit
finish-args:
- --filesystem=home:rw
- --share=network
modules:
- name: fzf
buildsystem: simple
build-commands:
- tar -xvf fzf-0.33.0-linux_amd64.tar.gz
- install -Dm755 fzf ${FLATPAK_DEST}/bin/fzf
sources:
- type: file
url: https://github.com/junegunn/fzf/releases/download/0.33.0/fzf-0.33.0-linux_amd64.tar.gz
sha256: bcf2f4ba957cce15cea1546f48cdd3bfe9b5dc9a6e80ccc400314bda171466f3
- name: git
buildsystem: simple
build-commands:
- install -Dm755 $(which git) ${FLATPAK_DEST}/bin/
- install -Dm755 $(which git-cvsserver) ${FLATPAK_DEST}/bin/
- install -Dm755 $(which git-receive-pack) ${FLATPAK_DEST}/bin/
- install -Dm755 $(which git-shell) ${FLATPAK_DEST}/bin/
- install -Dm755 $(which git-upload-archive) ${FLATPAK_DEST}/bin/
- install -Dm755 $(which git-upload-pack) ${FLATPAK_DEST}/bin/
- name: ugit
buildsystem: simple
build-options:
build-commands:
- chmod +x ugit
- install -Dm755 ugit ${FLATPAK_DEST}/bin/ugit
- install -Dm755 org.Bhupesh-V.ugit.desktop ${FLATPAK_DEST}/share/applications/org.Bhupesh-V.ugit.desktop
sources:
- type: git
url: https://github.com/Bhupesh-V/ugit
tag: v5.3
commit: 14da50780e696e758bf362489496b74901f84cc1
- type: file
path: org.Bhupesh-V.ugit.desktop

View file

@ -1,5 +0,0 @@
[Desktop Entry]
Name=ugit
Exec=ugit
Type=Application
Terminal=true