lakshmen
lakshmen

Reputation: 29084

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?

Upvotes: 3

Views: 393

Answers (2)

Hugo
Hugo

Reputation: 12914

have you tried git reset origin/master?

or change origin/master to a commit id if you have some not pushed commits you would like to keep.

Upvotes: 1

Amber
Amber

Reputation: 527023

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.

Upvotes: 4

Related Questions