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

Re: git undo # last command

From
Jeff King <peff@peff.net>
Date
Aug 16, 2013, 13:26 UTC
Message-ID
<20130816132612.GF20138@sigill.intra.peff.net>
In-Reply-To
<CAAUyY9ADW2iHVWhTGcTF8j0hrdumpBcLv_mLo0y8VDAyBpftJQ@mail.gmail.com>
On Fri, Aug 16, 2013 at 10:55:06AM +0200, Saša Tomić wrote:
Show 8 quoted lines
> it just occurred to me -- the command that I would REALLY like to have
> is simple:
> 
>   git undo
> 
> which 'undo'es the last action that has not been pushed yet --
> whichever the action is. Similarly to the 'back' button in the
> browser.

One problem with such simplicity is that you need to define what an "action" is. If I make a commit, the undo is probably "reset HEAD@{1}". If I fetch a ref, would undo move backwards? What if I fetch multiple refs with one command; do we undo all of them? How about during a multiple-command operation, like a rebase? Does an undo affect the last commit, or the whole rebase?

I think these questions can be answered (though I am not sure of the best answer for most of them, nor even if there is a single answer that covers all situations), but I think a starting point for any "undo" command would be coming up with a list of what constitutes an action, how we record the list of actions, and then an appropriate "undo" reaction for each action.

-Peff
Previous: Saša TomićNext: Saša Tomić
Message 2 of 4 in “git undo # last command”
  1. Saša TomićAug 16, 2013
  2. Jeff KingAug 16, 2013
  3. Saša TomićAug 16, 2013
  4. Fredrik GustafssonAug 16, 2013

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.