gitui-org / gitui-org/gitui

Branching from a specific commit

Aperta
#2,292 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
feature-request
Lingua principale
Rust
Stelle
22.5k
Fork
773
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## Scenario

Consider I made a mistake when discarding commits.
I completely reset the last 3 commits:

```bash
git reset --hard HEAD~3
```

I went back to the working directory and almost had a heart attack when the `my.head` file was gone.
I used `git log` and the commit that created the file is no longer listed.

This file is very important and cannot be lost.

## How to recover

We know it's still possible to recover.

I consult `git reflog` and find out I discarded more commits than intended.
I reset 3 but it should have been 2. The third one was the one that created `my.head`.

To recover, I note the hash shown by `git reflog` for that third commit. And I create a new branch from it.

```bash
git checkout -b recovery 4f02a1d
```

> [!note]
> Even though `git reset --hard ` completely removes changes, what `git` does is mark these changes for future deletion done automatically by `git gc`.
> This makes the changes invisible to `git log` but still present in `git reflog` for some time.

Now I can merge `recovery` branch into `main` branch and get `my.head` back in my working directory.

```bash
git checkout main
git rebase recovery
```

## `gitui`

I didn't find in `gitui` a feature to consult `reflog` or to create a new `branch` from a commit number. I suggest a feature that achieves both goals.

The characteristics of this feature are:

- Provide comprehensiveness
- Not create unnecessary redundancy for existing options in `gitui`
- Provide user-friendly and secure process.


Just as an introduction on how the feature could be implemented, it could be assigned under the `Branches [b]` screen, as a new option like `Create from []`.
`Create from []` opens a screen with two options:

- Type the original `hash` for the new branch
- Display `reflog` and allow scrolling to locate and select the origin for the new branch.

> [!tip]
> Allowing users to create a copy of a previous data snapshot is reassuring for the user. It can be understood as a `panic button`.
> This reinforces the guarantee of not losing data.

## System

OS: Ubuntu 22.04
`gitui` Version: 0.23.3

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.