# difference between "git reset --hard" and "git checkout -f"

3 messages from 2008-04-30 to 2008-04-30. Participants: Sitaram Chamarty, Miklos Vajna, Johannes Sixt.
Thread: https://gitlist.dev/t/13333

## Sitaram Chamarty, 2008-04-30 11:37

Subject: difference between "git reset --hard" and "git checkout -f"
Message-ID: <2e24e5b90804300437t39ac16a6ga3cbe0b91d7e5565@mail.gmail.com>
URL: https://gitlist.dev/e/2e24e5b90804300437t39ac16a6ga3cbe0b91d7e5565%40mail.gmail.com

```
I have two questions:

(1) as in the subject line, what's the difference between these two
commands?  (I'm talking about those exact commands, not variations).
I am unable to see any.

(2) shouldn't one of these have an option to throw away untracked
files also, to get to a pristine HEAD-eqvt state?  Or is it better to
force user to use git clean separately for that?

Thanks,

Sitaram

```

## Miklos Vajna, 2008-04-30 12:16

Subject: Re: difference between "git reset --hard" and "git checkout -f"
Message-ID: <20080430121606.GA23672@genesis.frugalware.org>
URL: https://gitlist.dev/e/20080430121606.GA23672%40genesis.frugalware.org
In-Reply-To: <2e24e5b90804300437t39ac16a6ga3cbe0b91d7e5565@mail.gmail.com>

```
On Wed, Apr 30, 2008 at 05:07:40PM +0530, Sitaram Chamarty <sitaramc@gmail.com> wrote:
> I have two questions:
> 
> (1) as in the subject line, what's the difference between these two
> commands?  (I'm talking about those exact commands, not variations).
> I am unable to see any.

git checkout is the tool to check out a branch or paths. git reset is to
reset HEAD (and as a side effect the working directory as well). so i
think only the sematics differ, there is no difference in practice.

> (2) shouldn't one of these have an option to throw away untracked
> files also, to get to a pristine HEAD-eqvt state?  Or is it better to
> force user to use git clean separately for that?

i would say so. we already require (by default) to use git clean -f, as
it may wipe out your work (in case you forgot to git add some important
files), so just adding an other option to perform this dangerous
operation would not be good imho.

```

## Johannes Sixt, 2008-04-30 12:47

Subject: Re: difference between "git reset --hard" and "git checkout -f"
Message-ID: <48186A77.9040601@viscovery.net>
URL: https://gitlist.dev/e/48186A77.9040601%40viscovery.net
In-Reply-To: <20080430121606.GA23672@genesis.frugalware.org>

```
Miklos Vajna schrieb:
> On Wed, Apr 30, 2008 at 05:07:40PM +0530, Sitaram Chamarty <sitaramc@gmail.com> wrote:
>> (1) as in the subject line, what's the difference between these two
>> commands?  (I'm talking about those exact commands, not variations).
>> I am unable to see any.
> 
> git checkout is the tool to check out a branch or paths. git reset is to
> reset HEAD (and as a side effect the working directory as well). so i
> think only the sematics differ, there is no difference in practice.

Moreover, if you are in the middle of a merge (e.g. when there are merge
conflicts, or after git merge --no-commit), git reset --hard forgets about
the merge, but git checkout -f does not; hence, a git commit after the
latter would create a merge commit, which is usually not what you want.

-- Hannes

```
