git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 28, 2015, 22:58 UTC
Message-ID
<xmqqr3lib189.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20150928223607.15594.qmail@ns.horizon.com>
"George Spelvin" <linux@horizon.com> writes:
Show 10 quoted lines
> Junio C Hamano <gitster@pobox.com> 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.
Previous: George SpelvinNext: George Spelvin
Message 10 of 11 in “Why not git reset --hard <path>?”
  1. George SpelvinSep 28, 2015
  2. Junio C HamanoSep 28, 2015
  3. Jacob KellerSep 28, 2015
  4. Junio C HamanoSep 28, 2015
  5. Theodore Ts'oSep 28, 2015
  6. Jacob KellerSep 29, 2015
  7. George SpelvinSep 29, 2015
  8. Philip OakleySep 29, 2015
  9. George SpelvinSep 28, 2015
  10. Junio C HamanoSep 28, 2015
  11. George SpelvinSep 28, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.