git reset --hard and uncommitted files in index
Hi,
Today I was working on a script that modify many files on a repository, therefore during testing phase I needed to reset --hard to get back to the last commit. This operation does not affect untracked files.
Since i was going to commit the script, at some point I decided to add it to the index so I could track/revert changes to it. On the next reset Git deleted the script.
Fortunately "git add" creates an object that I could easily recover (thanks to wereHamster on #git for pointing that out), however I was wondering if it's really the desired behavior to *delete* a file that have been added to the index but isn't on the previous commit? Shouldn't git just unstage it?
--
Thomas
Quoted 8 lines · Thomas Guyot-Sionnest
Today I was working on a script that modify many files on a repository, therefore during testing phase I needed to reset --hard to get back to the last commit. This operation does not affect untracked files.
Since i was going to commit the script, at some point I decided to add it to the index so I could track/revert changes to it. On the next reset Git deleted the script.
Quoted 5 lines
Fortunately "git add" creates an object that I could easily recover (thanks to wereHamster on #git for pointing that out), however I was wondering if it's really the desired behavior to *delete* a file that have been added to the index but isn't on the previous commit? Shouldn't git just unstage it?
No, the behavior is by design. Its purpose is to return the working directory to a clean slate. For example, after a conflicted merge the merged branch may have brought new files, but you wouldn't want to keep them around after the cleanup.
'git reset --hard' is "do what I say", not "do what I mean". ;-)
-- Hannes
Heya,
Quoted 1 line · Thomas Guyot-Sionnest
Shouldn't git just unstage it?
You can do that too, 'git reset && git reset --hard' will not touch untracked files. The first will unstage all your changes, the second will blow away all changes to tracked files.
Signature · 3 lines
Cheers, Sverre Rabbelier