Skip to content

Branching from a specific commit #2292

Open
@daedalus-rwx

Description

@daedalus-rwx

Scenario

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

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.

git checkout -b recovery 4f02a1d

Note

Even though git reset --hard <something> 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.

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 [<shortcut>].
Create from [<shortcut>] 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions