Recover commit lost during commit amend

884 Views Asked by At

I've made a mistake I guess

Yesterday I created a new branch (feature/crud-suppliers), then yesterday and today I worked on that branch. 30 minutes ago, after I finished my changes I added the files modified and did a git commit --amend --no-edit then I remembered that I didn't commit anything before, so I wanted to add a message to the commit.

I thought that with git rebase -i HEAD~2 I could go inside and change the message, but the commit wasn't there, so i just pressed to exit ctrl+X and noticed that it completed the rebase..

After that my edits disapear, few minutes ago I pushed everything to check if i could find the edits on github but no luck.

I tried git reflog but checking the hash before the rebase didn't show my edits.

this is my git reflog:

637b687 (HEAD, master) HEAD@{0}: checkout: moving from feature/crud-suppliers to 637b687
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{1}: checkout: moving from 3f5931ac661a4d4ee983fe0a173ae309a874be83 to feature/crud-suppliers
3f5931a HEAD@{2}: checkout: moving from 8dd9857224adf665df1d5d981c067d6068c3bea6 to 3f5931a
8dd9857 HEAD@{3}: checkout: moving from feature/crud-suppliers to 8dd9857
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{4}: checkout: moving from feature/crud-products to feature/crud-suppliers
9ed4250 (origin/feature/crud-products, feature/crud-products) HEAD@{5}: checkout: moving from develop to feature/crud-products
069daa3 (origin/develop, develop) HEAD@{6}: checkout: moving from feature/crud-suppliers to develop
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{7}: rebase -i (finish): returning to refs/heads/feature/crud-suppliers
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{8}: rebase -i (start): checkout HEAD~2
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{9}: checkout: moving from 3f5931ac661a4d4ee983fe0a173ae309a874be83 to feature/crud-suppliers
3f5931a HEAD@{10}: checkout: moving from a55e9d98dc253dfb72461e7f4ef07dc815df0400 to 3f5931a
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{11}: checkout: moving from feature/crud-suppliers to a55e9d9
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{12}: rebase -i (finish): returning to refs/heads/feature/crud-suppliers
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{13}: rebase -i (start): checkout HEAD~2
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{14}: rebase -i (finish): returning to refs/heads/feature/crud-suppliers
a55e9d9 (origin/feature/crud-suppliers, feature/crud-suppliers) HEAD@{15}: rebase -i (pick): CRUD employees
3f5931a HEAD@{16}: rebase -i (pick): Added new ways to retreive company informations
8dd9857 HEAD@{17}: rebase -i (pick): Created company user views
faedafc HEAD@{18}: rebase -i (pick): Changed email link to reset password
9b54992 HEAD@{19}: rebase -i (start): checkout HEAD~2
b69bfb0 HEAD@{20}: commit (amend): Merge pull request #11 from alebuffoli/feature/crud-employees
069daa3 (origin/develop, develop) HEAD@{21}: checkout: moving from feature/crud-products to feature/crud-suppliers


Update

The method suggested below worked, but as a matter of fact, before to receive any reply on this question I was able to recover all my lost changes with the history function on my editor (Pycharm), so I guess to mention it if you are in a similar situation and cannot recover the changes with the methods below.

1

There are 1 best solutions below

1
On BEST ANSWER

git also keeps a log for individual branches : run

git reflog feature/crud-suppliers

to view only actions that moved that branch.


By default : git rebase completely drops merge commits. If your changes were stored in commit Merge pull request #11 from ..., then running git rebase HEAD~2 would discard that commit.

You can use -r|--rebase-merges to keep them.