Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undoing my mistake using git reset --hard

I accidentally added some files using git add . . I would like to remove the changes using git reset --hard. When I type so, I get this error message.

fatal: Failed to resolve 'HEAD' as a valid ref

I tried typing git reset --hard HEAD^. Still not able to solve it.

How do I solve it?

like image 201
lakshmen Avatar asked Dec 07 '25 13:12

lakshmen


1 Answers

It sounds like you're trying to construct the initial commit in a newly created repo.

Since you haven't actually committed anything yet, you can just start over by removing the .git directory and running git init again.


Alternatively, you can try git rm --cached . to remove the files from the index.

like image 83
Amber Avatar answered Dec 10 '25 03:12

Amber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!