{"thread":{"id":"36190","subject":"Should 'git reset --hard' keep a stashed backup?","startedAt":"2014-03-16T21:22:42Z","lastAt":"2014-03-16T23:14:57Z","messageCount":2,"participants":["Philip Oakley","Duy Nguyen"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"236843","messageId":"EF7B8A31C59946F8821697F3BA129043@PhilipOakley","threadId":"36190","inReplyTo":null,"subject":"Should 'git reset --hard' keep a stashed backup?","fromName":"Philip Oakley","fromEmail":"philipoakley@iee.org","sentAt":null,"receivedAt":"2014-03-16T21:22:42Z","isPatch":false,"sender":{"key":"philipoakley@iee.email","avatar":"https://avatars.githubusercontent.com/u/914343?v=4"},"body":"A bike-shedding thought:\nMany inexperienced users do a 'git reset --hard' only to discover they \nhave deleted something important and want it back. (e.g. git-users \nyesterday [1])\n\nOne possible option is that Git could \"stash\" the current work-tree \ncontents (git stash create) into a commit and store its commit_id in a \nsuitable file/variable such as RESET_HARD_HEAD (or GIT_RESET_HARD_HEAD), \nsimilar to FETCH_HEAD & MERGE_HEAD, so that it would be relatively easy \nto recover the prior state.\n\nBy only storing the id in the file/env it would be overwritten on each \nusage, and the loose commits would be garbage collected eventually.\n\nA suitable config variable would allow it to be enabled/disabled as \nappropriate to the user. (Perhaps enabled by default eventually?)\n\nGiven the prevalence of 'git reset --hard' within internet forum advice, \nwould something like this be useful?  It could even be wrapped into a \nGSoC project.\n\n--\n\nPhilip\n\n\n[1] https://groups.google.com/forum/#!topic/git-users/CwQyfwnzCVM \n"},{"id":"236848","messageId":"CACsJy8CGvwEk4whaiEn5ccTyRKD4ZwUXqYVM9hTGfU7tYUdX=A@mail.gmail.com","threadId":"36190","inReplyTo":"EF7B8A31C59946F8821697F3BA129043@PhilipOakley","subject":"Re: Should 'git reset --hard' keep a stashed backup?","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2014-03-16T23:14:57Z","receivedAt":"2014-03-16T23:14:57Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Mar 17, 2014 at 5:17 AM, Philip Oakley <philipoakley@iee.org> wrote:\n> A bike-shedding thought:\n> Many inexperienced users do a 'git reset --hard' only to discover they have\n> deleted something important and want it back. (e.g. git-users yesterday [1])\n>\n> One possible option is that Git could \"stash\" the current work-tree contents\n> (git stash create) into a commit and store its commit_id in a suitable\n> file/variable such as RESET_HARD_HEAD (or GIT_RESET_HARD_HEAD), similar to\n> FETCH_HEAD & MERGE_HEAD, so that it would be relatively easy to recover the\n> prior state.\n\nA while back I started to implement \"undo\" function for \"git add\". I\nthink we could do the same here, when reset --hard is issued, store\ncurrent SHA-1 in index to an index extension, also hash overwritten\nfiles in worktree and store it in the index extension as well. \"reset\n--undo\" can bring it back. Experienced user can turn this off via\nconfig variable, but it's default to on.\n\n>\n> By only storing the id in the file/env it would be overwritten on each\n> usage, and the loose commits would be garbage collected eventually.\n\nWe have similar ideas, except I choose to store in the index instead.\n\n>\n> A suitable config variable would allow it to be enabled/disabled as\n> appropriate to the user. (Perhaps enabled by default eventually?)\n\nYes. We could even bundle it to an advice.* knob. Experienced users\nwill usually turn the advice off (and this behavior will be gone as\nthe result).\n\n> Given the prevalence of 'git reset --hard' within internet forum advice,\n> would something like this be useful?  It could even be wrapped into a GSoC\n> project.\n\nWe could go further to provide \"git undo\" interface that covers other\nareas as well, easier to discover than \"reset --undo\", but I'm not\nsure how this interface should work..\n-- \nDuy\n"}]}