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

Feedback on git-restore

From
PVPoughon Victor <victor.poughon@cnes.fr>
Date
May 15, 2019, 09:38 UTC
Message-ID
<3E55146A6A81B44A9CB69CAB65908CEA6B91353C@TW-MBX-P01.cnesnet.ad.cnes.fr>
Hi
I came across a description of a new git command currently in development called 'git restore'. Since it's still not out, and the original poster [1] seemed to ask for feedback, I though I'd send some here. Hope that's ok!
Reading the documentation [2] I find it very confusing. In particular when comparing the following two commands:

$ git restore --staged file $ git restore --worktree file

With the current proposal, the first will restore the index from HEAD, while the second will restore the worktree from the index. In other words, the source for the restore is different in both commands, even though neither specify a source! This means that git-restore really does two different things depending on some other not obvious context. Unfortunately that's typical of the (often criticized) obscure interface of git. To be fair that behavior is documented in [2]. But still, having a variable default value for --source depending on other arguments is very confusing.
So in summary, I'd make two recommendations for this command's UX:
1. Make --source default value always HEAD if unspecified
2. Rename --staged to --index
Some examples of those:

$ git restore --index file # reset the index from HEAD $ git restore --worktree file # reset the worktree from HEAD $ git restore --worktree --source=index file # reset the worktree from the index $ git restore --index --worktree file # reset both the index and worktree from HEAD $ git restore file # reset the worktree from HEAD

[1] https://news.ycombinator.com/item?id=19907960 [2] https://github.com/git/git/blob/pu/Documentation/git-restore.txt

Best, Victor

Next: Duy Nguyen
Message 1 of 8 in “Feedback on git-restore”
  1. Poughon VictorMay 15, 2019
  2. Duy NguyenMay 15, 2019
  3. Ævar Arnfjörð BjarmasonMay 15, 2019
  4. Duy NguyenMay 15, 2019
  5. Junio C HamanoMay 16, 2019
  6. Philip OakleyMay 16, 2019
  7. Duy NguyenMay 16, 2019
  8. Philip OakleyMay 18, 2019

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.