Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git (sourcetree) go back to commit that has not been pushed and was 'reversed' accidentally

I'm still quite new to git revisioning and maybe just lost plenty of work (but I hope there is a way to go back, that's why I'm asking here).

I use SourceTree on OsX for git revisioning. I didn't commit for quite a long while and now just wanted to commit plenty of changes. I selected to push immediately after the commit. When the push took very long, I checked my folder and noticed that I accidentally had selected a big build folder that should not be checked in. So I cancelled the push (I got a message something like commit was successful but push was not).

So, even though I interrupted the push, I still saw this commit in my master branch. I wanted to undo this, so I could commit again (this time without the build folder). I rightclicked on the commit and there was a 'Reverse commit...' option, which I clicked. But instead of removing this revision, it added another revision labeled 'Revert "Name of the commit i wanted to undo"'.

Bad thing is - now all my local changes seem to have gone and my files are on the state from one month ago.

since the commit (of which I cancelled the push) is still in the list, I wonder if I can somehow go back there? Is there any chance to get the local changes I made during last month back? I do have a backup of my files, but that's also almost two weeks old.

This is how sourcetree currently looks like:

SourceTree Screenshot

as you can see, the previous successful commit/push i made was on may 20. Then today I tried to commit/push new features, but interrupted during pushing. Then i 'reversed' this (interrupted) commit, which aparently reset all my local files to the state from may 20. Sourcetree shows that there are 2 Pushs to make (which I assume are the interrupted push and the push for the 'reverse' commit).

Is there any way I can go back to my local state I had right before committing today?

Thank you so much

like image 458
matthias_buehlmann Avatar asked Feb 16 '23 06:02

matthias_buehlmann


1 Answers

First undo the revert commit, throwing away the changes it created:

git reset --hard HEAD^

Then undo the updated render graphics commit, but keep those changes in your working tree (your local files):

git reset HEAD^
like image 183
Klas Mellbourn Avatar answered Feb 18 '23 19:02

Klas Mellbourn