{"thread":{"id":"34710","subject":"git undo # last command","startedAt":"2013-08-16T08:55:06Z","lastAt":"2013-08-16T20:29:04Z","messageCount":4,"participants":["Saša Tomić","Jeff King","Fredrik Gustafsson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"225317","messageId":"CAAUyY9ADW2iHVWhTGcTF8j0hrdumpBcLv_mLo0y8VDAyBpftJQ@mail.gmail.com","threadId":"34710","inReplyTo":null,"subject":"git undo # last command","fromName":"Saša Tomić","fromEmail":"tomic80@gmail.com","sentAt":"2013-08-16T08:55:06Z","receivedAt":"2013-08-16T08:55:06Z","isPatch":false,"sender":{"key":"tomic80@gmail.com","avatar":null},"body":"Hi to all,\n\nI've been using git for some time now, but I'm in no way a git expert.\nI typically hack my way through the variety of commands that git\nprovides. I believe that most git users work similarly.\n\nit just occurred to me -- the command that I would REALLY like to have\nis simple:\n\n  git undo\n\nwhich 'undo'es the last action that has not been pushed yet --\nwhichever the action is. Similarly to the 'back' button in the\nbrowser.\n\nCurrently, when I make a mistake, I have to search the net to find the\n*right* command that will undo my last action/command. That's boring\nand time consuming. git undo would make things much easier, I believe.\n\nWould creating such command be possible? I guess that 'behind the\nscenes', the command could analyze the reflog and act based on that.\n\n\nWhat do you think?\n\n-- \nBest regards,\nSaša\n"},{"id":"225342","messageId":"20130816132612.GF20138@sigill.intra.peff.net","threadId":"34710","inReplyTo":"CAAUyY9ADW2iHVWhTGcTF8j0hrdumpBcLv_mLo0y8VDAyBpftJQ@mail.gmail.com","subject":"Re: git undo # last command","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-08-16T13:26:12Z","receivedAt":"2013-08-16T13:26:12Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Aug 16, 2013 at 10:55:06AM +0200, Saša Tomić wrote:\n\n> it just occurred to me -- the command that I would REALLY like to have\n> is simple:\n> \n>   git undo\n> \n> which 'undo'es the last action that has not been pushed yet --\n> whichever the action is. Similarly to the 'back' button in the\n> browser.\n\nOne problem with such simplicity is that you need to define what an\n\"action\" is. If I make a commit, the undo is probably \"reset HEAD@{1}\".\nIf I fetch a ref, would undo move backwards? What if I fetch multiple\nrefs with one command; do we undo all of them? How about during a\nmultiple-command operation, like a rebase? Does an undo affect the last\ncommit, or the whole rebase?\n\nI think these questions can be answered (though I am not sure of the\nbest answer for most of them, nor even if there is a single answer that\ncovers all situations), but I think a starting point for any \"undo\"\ncommand would be coming up with a list of what constitutes an action,\nhow we record the list of actions, and then an appropriate \"undo\"\nreaction for each action.\n\n-Peff\n"},{"id":"225345","messageId":"CAAUyY9DqCrpMJPKKmzLGWVkoJRPfA5URLQz0uyTLZCPe6QKe5w@mail.gmail.com","threadId":"34710","inReplyTo":"20130816132612.GF20138@sigill.intra.peff.net","subject":"Re: git undo # last command","fromName":"Saša Tomić","fromEmail":"tomic80@gmail.com","sentAt":"2013-08-16T14:21:59Z","receivedAt":"2013-08-16T14:21:59Z","isPatch":false,"sender":{"key":"tomic80@gmail.com","avatar":null},"body":"On Fri, Aug 16, 2013 at 3:26 PM, Jeff King <peff@peff.net> wrote:\n> On Fri, Aug 16, 2013 at 10:55:06AM +0200, Saša Tomić wrote:\n>\n>> it just occurred to me -- the command that I would REALLY like to have\n>> is simple:\n>>\n>>   git undo\n>>\n>> which 'undo'es the last action that has not been pushed yet --\n>> whichever the action is. Similarly to the 'back' button in the\n>> browser.\n>\n> One problem with such simplicity is that you need to define what an\n> \"action\" is. If I make a commit, the undo is probably \"reset HEAD@{1}\".\n> If I fetch a ref, would undo move backwards? What if I fetch multiple\n> refs with one command; do we undo all of them? How about during a\n> multiple-command operation, like a rebase? Does an undo affect the last\n> commit, or the whole rebase?\n>\n> I think these questions can be answered (though I am not sure of the\n> best answer for most of them, nor even if there is a single answer that\n> covers all situations), but I think a starting point for any \"undo\"\n> command would be coming up with a list of what constitutes an action,\n> how we record the list of actions, and then an appropriate \"undo\"\n> reaction for each action.\n>\n> -Peff\n\n\nSimplicity rarely comes for free. But simplicity may not mean the same\nto a new git user, and to an experienced git user or developer.\n\nThe beauty of \"undo\" operation/action is that there is only one\ncommand to be learned. Whatever you do, you can \"undo\".\ngit commit ==> git reset --soft HEAD^\ngit add <file> ==> git reset HEAD <file>\ngit add <directory> ==> git rm -r --cached <directory>\n\nHowever, the command that you have to do may not be easy to find in\ndocumentation or online.\n\nA simple workaround, that I several times employed, is to make a\nbackup of the repo, and to play with the repo after that. If anything\ngoes wrong, I restore the backup.\n\nBut git should not force me to do this. Git clearly can do more and better.\n\nAnyway, I believe that \"undo\" should revert the *last* command typed\nin and executed by the user, even if it's a multi-step operation such\nas rebase. Of course, it would be of great help even if a user has to\nrun \"git undo\" several times for one \"git rebase\". You're certainly\nmore experienced with git under the hood, so you know which one is\neasier to implement.\n\nI would be happy to help in making a list of actions and corresponding\nundo \"reactions\".\n\n-- st\n"},{"id":"225354","messageId":"20130816202904.GA21779@paksenarrion.iveqy.com","threadId":"34710","inReplyTo":"CAAUyY9DqCrpMJPKKmzLGWVkoJRPfA5URLQz0uyTLZCPe6QKe5w@mail.gmail.com","subject":"Re: git undo # last command","fromName":"Fredrik Gustafsson","fromEmail":"iveqy@iveqy.com","sentAt":"2013-08-16T20:29:04Z","receivedAt":"2013-08-16T20:29:04Z","isPatch":false,"sender":{"key":"iveqy@iveqy.com","avatar":"https://avatars.githubusercontent.com/u/761743?v=4"},"body":"On Fri, Aug 16, 2013 at 04:21:59PM +0200, Saša Tomić wrote:\n> git commit ==> git reset --soft HEAD^\nThe commit does still exists, you can find it in the reflog. This is\nimportant if you for example commits a huge file and wants to remove it.\nThat commit needs to be gc:ed too, and this is dangerous...\n\nIt's a not common, but often asked, question on #git@freenode . And for\nmany it's hard to understand why a git rm doesn't shrink their repo.\n\nAlso consider that many git commands relies on eachother. For example\nthe submodule scripts uses git checkout, clone, etc.\n-- \nMed vänliga hälsningar\nFredrik Gustafsson\n\ntel: 0733-608274\ne-post: iveqy@iveqy.com\n"}]}