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

Why not git reset --hard <path>?

From
GSGeorge Spelvin <linux@horizon.com>
Date
Sep 28, 2015, 20:34 UTC
Message-ID
<20150928203449.29024.qmail@ns.horizon.com>

I was applying an old forgotten stash to see if there were any edits in it I wanted to preserve, and my old changes to one file made no sense any more. I wanted to drop then all and keep the version in HEAD.

I'd been using git reset <path> after resolving conflicts, to leave the changes in the same un-staged state they were before the stash, so I tried using "git reset --hard crypto/842.c" to throw away my local changes.

And I got fatal: Cannot do hard reset with paths.

So I did "git reset <path>" followed by "git checkout <path>", which achieved what I wanted.

But what I don't understand is why git reset couldn't do it for me in one step.

I understand that "git reset --soft" makes no sense with a path, but why not --hard?

Next: Junio C Hamano
Message 1 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.