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

Re: Reset by checkout?

From
Kevin Bracey <kevin@bracey.fi>
Date
Jun 9, 2014, 20:12 UTC
Message-ID
<5396152F.4020704@bracey.fi>
In-Reply-To
<241E3E5EB7AE44E6821EA5DFAA24C28F@PhilipOakley>
On 07/06/2014 17:52, Philip Oakley wrote:
Show 9 quoted lines
>
>
> Just to say there has been a similar confusion about 'git reset' 
> reported on the Git Users group for the case of reset with added 
> (staged), but uncommitted changes being wiped out, which simlarly 
> reports on the difficulty of explaining some of the conditions 
> especially when some are wrong ;-)
>
> https://groups.google.com/forum/#!topic/git-users/27_FxIV_100

I'm coming around to the view that "git reset <mode>" should be (almost) demoted to plumbing, leaving only the "reset <file>" that reverses "add <file>" as everyday Porcelain.

I think "reset --keep" and "--merge" were a step in the wrong direction, at least for the Porcelain - trying to make reset <mode> "more useful", rather than less necessary. Normal users shouldn't be needing to touch these hard-to-explain-and-slightly-dangerous commands.

The addition of "--abort" to merge and other commands was much more solid. They helped a lot, and I think we should follow that model by adding "--undo" to various commands. That would mop up all the common "reset"s, in conjunction with Atsushi's proposed "checkout -u" alternative to -B, which I quite like.

Main few:

commit --undo = reset --soft HEAD^ merge --undo = reset --keep HEAD^ rebase --undo = reset --keep ORIG_HEAD [bug report: rebase -p doesn't set ORIG_HEAD reliably] pull --undo = merge/rebase --undo depending on rebase settings [could we go nuts and undo the fetch too?]

Bonus:
commit --amend --undo: reset --soft HEAD@{1}

The undos can also have a bit of extra veneer that checks the log/reflog for whether it matches the proposed undo, and also checks the upstream to see if the thing being undone is already public.

Given those, I honestly don't think I'd ever need to explain git reset <mode> to anyone again. Which would be nice...

(Note I propose no "--mixed" equivalent for the commit undos, but it's easy enough to follow the "commit --undo" with a normal "git reset". I'd rather re-document the normal git reset under "commit --undo" than add and document yet another option).

Kevin
Previous: Philip OakleyNext: Atsushi Nakagawa
Message 12 of 18 in “Reset by checkout?”
  1. Atsushi NakagawaMay 31, 2014
  2. Andreas SchwabMay 31, 2014
  3. Atsushi NakagawaJun 1, 2014
  4. Kevin BraceyMay 31, 2014
  5. Atsushi NakagawaJun 1, 2014
  6. Kevin BraceyJun 1, 2014
  7. Junio C HamanoJun 2, 2014
  8. Kevin BraceyJun 3, 2014
  9. Felipe ContrerasJun 3, 2014
  10. Atsushi NakagawaJun 7, 2014
  11. Philip OakleyJun 7, 2014
  12. Kevin BraceyJun 9, 2014
  13. Atsushi NakagawaJun 7, 2014
  14. Felipe ContrerasMay 31, 2014
  15. Felipe ContrerasMay 31, 2014
  16. Atsushi NakagawaJun 1, 2014
  17. Junio C HamanoJun 2, 2014
  18. Junio C HamanoJun 2, 2014

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.