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

Re: [PATCH/RFC] commit: new option to abort -a something is already staged

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Aug 20, 2018, 19:30 UTC
Message-ID
<20180820193007.GB31020@aiede.svl.corp.google.com>
In-Reply-To
<20180820154120.19297-1-pclouds@gmail.com>
Hi,
Nguyễn Thái Ngọc Duy wrote:
Show 7 quoted lines
> So many times I have carefully cherry picked changes to the index with
> `git add -p` then accidentally did `git commit -am ....` (usually by
> retrieving a command from history and pressing Enter too quickly)
> which destroyed beautiful index.
>
> One way to deal with this is some form of `git undo` that allows me to
> retrieve the old index.
Yes, I would love such an undo feature!

How would you imagine that this information would get stored? We can start with adding that and a low-level (plumbing) interface to it, to avoid being blocked on getting the user-facing (porcelain) "git undo" interface right. (Or we can go straight for the porcelain. It's fine for it to start minimal and gain switches later.)

[...]
Show 5 quoted lines
> Instead, let's handle just this problem for now. This new option
> commit.preciousDirtyIndex, if set to false, will not allow `commit -a`
> to continue if the final index is different from the existing one. I
> don't think this can be achieved with hooks because the hooks don't
> know about "-a" or different commit modes.

I frequently use "git commit -a" this way intentionally, so I would be unlikely to turn this config on. That leads me to suspect it's not a good candidate for configuration:

- it's not configuration for the sake of a transition period, since some
  people would keep it on forever
- it's not configuration based on different project needs, either
So configuration doesn't feel like a good fit.

It might be that I can switch my muscle memory to "git add -u && git commit", in which case this could work as a new default without configuration (or with configuration for a transition period). A separate commandline option "git commit -a --no-clobber-index" might make sense as well, since then I could pass --clobber-index to keep my current workflow. That would also follow the usual progression: introduce commandline option first, then config, then change default.

That said, I lean toward your initial thought, that this is papering over a missing undo feature. Can you say more about how you'd imagine undo working?

Thanks, Jonathan

Previous: Eric SunshineNext: Duy Nguyen
Message 4 of 28 in “commit: new option to abort -a something is already staged”
  1. commit: new option to abort -a something is already stagedNguyễn Thái Ngọc Duy, Aug 20, 2018
  2. Junio C HamanoAug 20, 2018
  3. Eric SunshineAug 20, 2018
  4. Jonathan NiederAug 20, 2018
  5. Duy NguyenAug 21, 2018
  6. Jonathan NiederAug 23, 2018
  7. Jonathan NiederAug 23, 2018
  8. Duy NguyenAug 23, 2018
  9. Junio C HamanoAug 23, 2018
  10. Jacob KellerAug 24, 2018
  11. Duy NguyenAug 24, 2018
  12. Jacob KellerAug 24, 2018
  13. Jacob KellerAug 24, 2018
  14. 0/1 Make 'git commit' not accidentally lose staged contentNguyễn Thái Ngọc Duy, Sep 16, 2018
  15. 1/1 commit: do not clobber the indexNguyễn Thái Ngọc Duy, Sep 16, 2018
  16. Junio C HamanoSep 17, 2018
  17. Duy NguyenSep 17, 2018
  18. Jeff KingSep 17, 2018
  19. Duy NguyenSep 17, 2018
  20. Jeff KingSep 18, 2018
  21. Jacob KellerSep 18, 2018
  22. Jeff KingSep 18, 2018
  23. Duy NguyenSep 19, 2018
  24. Jeff KingSep 19, 2018
  25. Junio C HamanoSep 17, 2018
  26. Jacob KellerSep 18, 2018
  27. Eckhard MaaßSep 18, 2018
  28. Jacob KellerSep 18, 2018

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.