Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undo git reset --soft to get my changes back?

I had some local changes in my directory that I committed using git commit. Later I realized that by mistake my changes broke my build. So I did a git reset --soft on my repo. But I screwed up, as I did not back up the changes that were all undone, as some of them did contain the new functionality that I wanted. Any help on how to undo a git reset --soft operation so that I can get my committed changes back.

like image 967
dennis Avatar asked Jan 10 '14 06:01

dennis


People also ask

How do I undo a git soft reset?

So, to undo the reset, run git reset HEAD@{1} (or git reset d27924e ). If, on the other hand, you've run some other commands since then that update HEAD, the commit you want won't be at the top of the list, and you'll need to search through the reflog .

How do I get my changes back after git reset?

We can use the command git fsck to recover the files after a hard reset.

Does git reset soft remove changes?

git reset --soft , which will keep your files, and stage all changes back automatically. git reset --hard , which will completely destroy any changes and remove them from the local directory.

Can you undo a hard git reset?

In most cases, yes. Depending on the state your repository was in when you ran the command, the effects of git reset --hard can range from trivial to undo, to basically impossible.


1 Answers

In $ git reflog you should find some of your commits. Once you find the latest commit that you want to move to

you should reset back to your commit id $ git reset _Your_Hash_ , as $ git reset --soft just reset the files and not the index or working tree.

like image 131
Franck Avatar answered Sep 30 '22 21:09

Franck