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

Re: Request: `git restore $commit $file` shouldn’t override uncommited changes

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 28, 2021, 09:10 UTC
Message-ID
<xmqqy2d2ai5w.fsf@gitster.g>
In-Reply-To
<I_ZK84DfFkUoO9FcqjidSjmsvktNt-k4tPiAGNIP5ztKjk0RQCfFmyRrRHaB414UaWsJO7kWPBcgHlRqAecH7r9mAj0TLm5k6T5_YzmiZ4c=@pm.me>
Robin Moussu <moussu.robin@pm.me> writes:
> On the contrary, if `--source $commit` is specified, I would like
> to get an error if $file has uncommitted changes.
Not necessarily.  I've done this number of times:
 - start from the current state (HEAD), make changes
 - end up making a mess that I'd rather not use.
 - realize that the endgame I seek is fairly close to the work I did
   for another branch.
 - "git checkout $that_branch -- $those_paths".

So, it is not cut-and-dried that it _always_ (or even _often_) is a mistake to try overwriting a working tree file with modifiations with a version of a file from commit that is not HEAD. It may be _always_ an error for your work habit. It would almost always be what I want in my experience for me.

Previous: Robin MoussuNext: Junio C Hamano
Message 4 of 5 in “Request: `git restore $commit $file` shouldn’t override uncommited changes”
  1. Robin MoussuApr 27, 2021
  2. Johannes AltmanningerApr 27, 2021
  3. Robin MoussuApr 28, 2021
  4. Junio C HamanoApr 28, 2021
  5. Junio C HamanoApr 28, 2021

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.