Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to unstage when there are no commits yet and "git restore –staged" returns an error "could not resolve HEAD"

I have created a Git repository locally by using the command git init.

Then mistakenly added all files for staging by entering git add .
But I want to unstage some files which I don’t want to commit.

But when I enter git restore --staged <file/folder name>, it states the following:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

fatal: could not resolve HEAD

I figured out this occurred due to my branch main having no commits yet. So, is it possible to exclude some files from staging before I can commit? If so, how can I achieve it?

>Solution :

Try git reset to remove all files from stage or git reset /path/to/file

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading