# git reset --hard and uncommitted files in index

3 messages from 2009-05-22 to 2009-05-22. Participants: Thomas Guyot-Sionnest, Johannes Sixt, Sverre Rabbelier.
Thread: https://gitlist.dev/t/19436

## Thomas Guyot-Sionnest, 2009-05-22 02:32

Subject: git reset --hard and uncommitted files in index
Message-ID: <gv52s4$e7h$1@ger.gmane.org>
URL: https://gitlist.dev/e/gv52s4%24e7h%241%40ger.gmane.org

```
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

```

## Johannes Sixt, 2009-05-22 06:43

Subject: Re: git reset --hard and uncommitted files in index
Message-ID: <4A1649A9.5090606@viscovery.net>
URL: https://gitlist.dev/e/4A1649A9.5090606%40viscovery.net
In-Reply-To: <gv52s4$e7h$1@ger.gmane.org>

```
Thomas Guyot-Sionnest schrieb:
> 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?

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

```

## Sverre Rabbelier, 2009-05-22 10:50

Subject: Re: git reset --hard and uncommitted files in index
Message-ID: <fabb9a1e0905220350i12d30d17udf078ec2ff76513a@mail.gmail.com>
URL: https://gitlist.dev/e/fabb9a1e0905220350i12d30d17udf078ec2ff76513a%40mail.gmail.com
In-Reply-To: <gv52s4$e7h$1@ger.gmane.org>

```
Heya,

On Fri, May 22, 2009 at 04:32, Thomas Guyot-Sionnest <dermoth@aei.ca> wrote:
> 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.

-- 
Cheers,

Sverre Rabbelier

```
