DEV Community

Mehak Saini
Mehak Saini

Posted on

Life saving Git commands

If you've committed some files in your local repository by mistake, you can undo it without losing your changes using the below command
1)Don't remove staged files

git reset --soft HEAD^
Enter fullscreen mode Exit fullscreen mode

2)Remove staged files

git reset HEAD^
Enter fullscreen mode Exit fullscreen mode

If you want to undo commit and lose all the changes, you can use

git reset --hard HEAD^
Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
rahxuls profile image
Rahul

These commands made my day lol

Collapse
 
mehaksaini11 profile image
Mehak Saini

Glad that helped!

Collapse
 
rahxuls profile image
Rahul

If you can edit the hashtags of this posts it would be awesome and in more detail about the commands so beginners will love it too.