DEV Community

loading...

Life saving Git commands

Mehak Saini
Java Developer by profession React enthusiast Currently exploring Blockchain
・1 min read

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

Discussion (3)

Collapse
rahxuls profile image
Rahul

These commands made my day lol

Collapse
mehaksaini11 profile image
Mehak Saini Author

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.