1

I started my project last month and committed about 150 times so far.

I pushed regularly too, my last push was this morning. So my work is not entirely lost but I'd like to know if a local recovery is possible, to recover my last commits (made after the push).

Here is what happened :

  • this morning, I reverted a single commit I had made 2 days ago. AFAIK, things went well. I kept on working and committing since.

  • this afternoon, I realised that my last 2 commits could be merged. So I tried git rebase --interactive. But Git answered :

I wonder if you are in the middle of another rebase.  If that is the
case, please try
        git rebase (--continue | --abort | --skip)
If that is not the case, please
        rm -fr ".git/rebase-merge"
and run me again.  I am stopping in case you still have something
valuable there.

I thought that I was due to my recent revert and did git rebase --abort. And I did wrong. Almost all my commits disappeard, git log only shows the first 3, last month. I suppose I had a pending rebase since then.

Is there a way to revert that rebase --abort ?

Thanks for reading and your help.

EDIT : here is the git status :

On branch master
Your branch is behind 'origin/master' by 147 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .vscode/
        __pycache__/
        main.py
        venv/

nothing added to commit but untracked files present (use "git add" to track)

EDIT: and here is the git reflog (I'd like to go back to f0b2519):

6b634e3 (HEAD -> master) HEAD@{1}: rebase -i (abort): updating HEAD
f0b2519 HEAD@{2}: commit: Add comments in params
da4f6b7 HEAD@{3}: commit: Add comments in params
850ac42 HEAD@{4}: commit: del pygame import in params, adapt main and pygi
3415a2f HEAD@{5}: commit: Put config content in params then delete config
98a8b89 HEAD@{6}: commit: Supress 'if main' in params
72803da (origin/master) HEAD@{7}: checkout: moving from 63cb88ae8d2f1547c7d18882084c06b73d892419 to master
63cb88a HEAD@{8}: checkout: moving from master to branch2
72803da (origin/master) HEAD@{9}: revert: Revert "Move switcher in pgi.press_key()"       
3f3ccb6 HEAD@{10}: checkout: moving from branch2 to master
63cb88a HEAD@{11}: checkout: moving from branch2 to branch2
63cb88a HEAD@{12}: revert: Revert "Move switcher in pgi.press_key()"
3f3ccb6 HEAD@{13}: checkout: moving from master to branch2
3f3ccb6 HEAD@{14}: checkout: moving from branch2 to master
3f3ccb6 HEAD@{15}: checkout: moving from master to branch2
3f3ccb6 HEAD@{16}: commit: Update requirements.txt
ccc6845 HEAD@{17}: commit: Edit docstring in pygameinterface
e4632d2 HEAD@{18}: commit: Linting on config and tool

EDIT : git reset --hard f0b2519 worked like a charm, what a relief ! Many thanks to all.

S_Crespo
  • 305
  • 1
  • 9

1 Answers1

2

Git reflog is most likely your friend and saviour.

Reference logs, or "reflogs", record when the tips of branches and other references were updated in the local repository. Reflogs are useful in various Git commands, to specify the old value of a reference. For example, HEAD@{2} means "where HEAD used to be two moves ago", master@{one.week.ago} means "where master used to point to one week ago in this local repository", and so on. See gitrevisions[7] for more details.

This is what ohshitgit.com has to say about reflog

You can use this to get back stuff you accidentally deleted, or just to remove some stuff you tried that broke the repo, or to recover after a bad merge, or just to go back to a time when things actually worked.

I've used reflog on several occassions when I've messed up.

Whit reflog you can go back in time, by checking out a specific point in the reflog this SO answer might clarify stuff more.

Daniel Figueroa
  • 10,348
  • 5
  • 44
  • 66