{"thread":{"id":"20490","subject":"[PATCH] Document 'stash clear' recovery via unreachable commits","startedAt":"2009-08-09T00:47:36Z","lastAt":"2009-08-09T09:26:52Z","messageCount":4,"participants":["Thomas Rast","Junio C Hamano","Björn Steinbrink","Sitaram Chamarty"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"120022","messageId":"9e8ddf7c6c4d4df4150bff0467b461bfff92a401.1249778711.git.trast@student.ethz.ch","threadId":"20490","inReplyTo":null,"subject":"[PATCH] Document 'stash clear' recovery via unreachable commits","fromName":"Thomas Rast","fromEmail":"trast@student.ethz.ch","sentAt":"2009-08-09T00:47:36Z","receivedAt":"2009-08-09T00:47:36Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Add an example to the stash documentation that shows how to quickly\nfind candidate commits among the 'git fsck --unreachable' output.\nUnless you have merges of branch names containing WIP, or edit your\nmerge messages to say WIP, there will be no false positives.\n\nSnippet written by Björn \"doener\" Steinbrink and me after zepolen_\nasked on IRC.\n\nSigned-off-by: Thomas Rast <trast@student.ethz.ch>\n---\n Documentation/git-stash.txt |   17 ++++++++++++++++-\n 1 files changed, 16 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt\nindex 1c64a02..2f5ca7b 100644\n--- a/Documentation/git-stash.txt\n+++ b/Documentation/git-stash.txt\n@@ -114,7 +114,8 @@ no conflicts.\n \n clear::\n \tRemove all the stashed states. Note that those states will then\n-\tbe subject to pruning, and may be difficult or impossible to recover.\n+\tbe subject to pruning, and may be impossible to recover (see\n+\t'Examples' below for a possible strategy).\n \n drop [-q|--quiet] [<stash>]::\n \n@@ -217,6 +218,20 @@ $ edit/build/test remaining parts\n $ git commit foo -m 'Remaining parts'\n ----------------------------------------------------------------\n \n+Recovering stashes that were cleared/dropped erroneously::\n+\n+If you mistakenly drop or clear stashes, they cannot be recovered\n+through the normal safety mechanisms.  However, you can try the\n+following incantation to get a list of stashes that are still in your\n+repository, but not reachable any more:\n++\n+----------------------------------------------------------------\n+git fsck --unreachable |\n+grep commit | cut -d\\  -f3 |\n+xargs git log --merges --no-walk --grep=WIP\n+----------------------------------------------------------------\n+\n+\n SEE ALSO\n --------\n linkgit:git-checkout[1],\n-- \n1.6.4.195.g3a1c2\n"},{"id":"120023","messageId":"7veirlbwws.fsf@alter.siamese.dyndns.org","threadId":"20490","inReplyTo":"9e8ddf7c6c4d4df4150bff0467b461bfff92a401.1249778711.git.trast@student.ethz.ch","subject":"Re: [PATCH] Document 'stash clear' recovery via unreachable commits","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-08-09T01:25:55Z","receivedAt":"2009-08-09T01:25:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thomas Rast <trast@student.ethz.ch> writes:\n\n> Add an example to the stash documentation that shows how to quickly\n> find candidate commits among the 'git fsck --unreachable' output.\n\nThanks.\n\n> Unless you have merges of branch names containing WIP, or edit your\n> merge messages to say WIP, there will be no false positives.\n\nThat may be true, but I suspect that people's stash entries that are worth\nsaving are given their own messages with \"git stash save 'message'\" and do\nnot necessarily say WIP.  I wish if there were a better way to identify\nthem, but I do not think of any offhand.\n"},{"id":"120024","messageId":"20090809022134.GA4141@atjola.homenet","threadId":"20490","inReplyTo":"7veirlbwws.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Document 'stash clear' recovery via unreachable commits","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2009-08-09T02:21:35Z","receivedAt":"2009-08-09T02:21:35Z","isPatch":true,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"On 2009.08.08 18:25:55 -0700, Junio C Hamano wrote:\n> Thomas Rast <trast@student.ethz.ch> writes:\n> \n> > Add an example to the stash documentation that shows how to quickly\n> > find candidate commits among the 'git fsck --unreachable' output.\n> \n> Thanks.\n> \n> > Unless you have merges of branch names containing WIP, or edit your\n> > merge messages to say WIP, there will be no false positives.\n> \n> That may be true, but I suspect that people's stash entries that are worth\n> saving are given their own messages with \"git stash save 'message'\" and do\n> not necessarily say WIP.  I wish if there were a better way to identify\n> them, but I do not think of any offhand.\n\nHere's what I have now:\n\ngit fsck --unreachable | grep commit | cut -d\\  -f3 |\nxargs git log --no-walk --merges \\\n\t--grep='^\\(WIP on \\|On \\)\\((no branch)\\|[^ ]\\+\\):'\n\nShould catch stashes with and without user-supplied messages and avoid\nmost false-positives. Drop the \"WIP on \" option from the grep to capture\njust those that have a user-supplied message.\n\nTo try really really hard to get stash stuff only, one could add some\nextra stuff to verify that the second parent's commit message is\n\"index on \\2:\" (\\2 being the second group from the above --grep). But\nthat's probably total overkill...\n\nBjörn\n"},{"id":"120044","messageId":"2e24e5b90908090226r1941c383j40853fd811ae3a73@mail.gmail.com","threadId":"20490","inReplyTo":"7veirlbwws.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] Document 'stash clear' recovery via unreachable commits","fromName":"Sitaram Chamarty","fromEmail":"sitaramc@gmail.com","sentAt":"2009-08-09T09:26:52Z","receivedAt":"2009-08-09T09:26:52Z","isPatch":true,"sender":{"key":"sitaramc@gmail.com","avatar":"https://avatars.githubusercontent.com/u/43316?v=4"},"body":"2009/8/9 Junio C Hamano <gitster@pobox.com>\n>\n> Thomas Rast <trast@student.ethz.ch> writes:\n\n\n>\n> > Unless you have merges of branch names containing WIP, or edit your\n> > merge messages to say WIP, there will be no false positives.\n>\n> That may be true, but I suspect that people's stash entries that are worth\n> saving are given their own messages with \"git stash save 'message'\" and do\n> not necessarily say WIP.  I wish if there were a better way to identify\n> them, but I do not think of any offhand.\n\ngitk $(git fsck | grep commit | cut -f3 -d' ') --since='1 week ago'\n\nThe --since clause limits the display to stashes lost recently; adjust to taste.\n\nA \"stash\" has a very recognisable, triangular, shape in the commit DAG\n-- with gitk you can visually find stashes really fast even if your\ntime limit is too broad or you have too many other kinds of\nunreachable commits perhaps due to too many rebase etc.\n"}]}