Subject: Re: Why not git reset --hard <path>?

From: Junio C Hamano <[email-masked]>
Date: Mon, 28 Sep 2015 15:58:14 -0700

"George Spelvin" <[email-masked]> writes:

> Junio C Hamano <[email-masked]> wrote:
>> "git checkout HEAD <pathspec>" is a 99% acceptable substitute for it
>> (the only case where it makes a difference is when you added a path to
>> the index that did not exist in HEAD).
>
> Er, wait a minute...
>
> "git checkout <tree-ish> <pathspec>" modifies the index?
>
> Damn, I've been using git for years and I never knew that.

... which would be an indication that the behaviour is most likely
the most natural one.

> But I just tested, and it does.  Damn, now I have to figure out
> how to "leapfrog" a file from history into the working tree without
> overwriting the index; that's occasionally useful.

... and indeed it is useful in some rare cases.  Either

    git diff <tree-ish> <pathspec> | git apply -R

or

    git checkout <tree-ish> <pathspec> &&
    git reset <pathspec>

are what I would use, and as an old-timer, the former is what I do.