Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does `git reset HEAD file` also check out the file?

Tags:

git

I mistakenly added a directory to git and when I followed the tip here to undo the add by doing git reset HEAD <file>, I was horrified to discover that the current working copy of one of the files, which has lots of changes (work!) in it, reverted back to the previous version!

As a result I lost several hours worth of work... :((

I thought that git reset HEAD <file> only "removes it from the current index without changing anything else. What did I miss?

Is git reset HEAD <file> supposed to also check out the file from HEAD?

How can I minimize the chances of something like this happening again in the future?

like image 203
Eternal Learner Avatar asked Jul 22 '11 12:07

Eternal Learner


2 Answers

Only git checkout -- <file> should have reverted the files in their previous stats. git reset HEAD <file> should only unstage the file, not revert its content.

like image 114
demental Avatar answered Oct 01 '22 18:10

demental


git reset unstages files from index. Maybe you added --hard option or used git checkout afterwards?

Quoting the git-reset manpage:

git reset [-q] [<commit>] [--] <paths>... This form resets the index entries for all to their state at . (It does not affect the working tree, nor the current branch.)

like image 20
Rafał Rawicki Avatar answered Oct 01 '22 18:10

Rafał Rawicki