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
Johannes Altmanninger <aclopte@gmail.com>
Date
Apr 27, 2021, 19:29 UTC
Message-ID
<20210427192906.7obdkopxwajqnv53@gmail.com>
In-Reply-To
<pYZzGPZTHnJjYBKrUAVGcso74I_xJgfzNpSwDN94fhYcDoOamp62-IFvxVrU056uw0txy3MTHYSwny_II0XY4trSY5_E25q7EXwhNHjy3VY=@pm.me>
> I would have expected that `git restore $commit $file` would copy the
> content of said file from another revision only if your don’t have
> uncommitted changes or to get an error.

The positional arguments to "git restore" are files. So that command will error unless a file called $commit exists. (You shell's tab completion should guide you here.) You can use the --source option to specify the commit.

> If it was really what I wanted to do, I would have expected to either do
> `git restore $file && git restore $commit $file`, directly `git restore
> --force $commit $file` or something similar.
Is your question that you expect a command like
	git restore --source=some-commit some-file

to error if you have uncommitted changes (to "some-file")? And instead you would run

	git restore some-file
	git restore --source=some-commit some-file
Previous: Robin MoussuNext: Robin Moussu
Message 2 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.