threads / discuss / 13333

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

Subject: difference between "git reset --hard" and "git checkout -f"

## tl;dr

3 messages between Apr 30, 2008 and Apr 30, 2008.

replies: 2people: 3as markdown or json

Sitaram Chamarty· Apr 30, 2008, 11:37 UTC · lore
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· Apr 30, 2008, 12:16 UTC · re: Sitaram Chamarty · lore

Re: difference between "git reset --hard" and "git checkout -f"

On Wed, Apr 30, 2008 at 05:07:40PM +0530, Sitaram Chamarty <sitaramc@gmail.com> wrote:
Show 5 quoted lines
> 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· Apr 30, 2008, 12:47 UTC · re: Miklos Vajna · lore

Re: difference between "git reset --hard" and "git checkout -f"

Miklos Vajna schrieb:
Show 8 quoted lines
> 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

← back to recent threads