{"thread":{"id":"8488","subject":"git-stash","startedAt":"2007-06-07T22:28:33Z","lastAt":"2007-06-08T06:52:45Z","messageCount":6,"participants":["Johannes Schindelin","Lars Hjemli","Bill Lear","Matthias Lederhofer"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"44270","messageId":"Pine.LNX.4.64.0706072328000.4046@racer.site","threadId":"8488","inReplyTo":null,"subject":"git-stash","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-06-07T22:28:33Z","receivedAt":"2007-06-07T22:28:33Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nI just was in the need for git-stash (for the 1e6th time this year), but \ninstead of writing a script, I though I'd try the \"!\" convention for \naliases. Works quite well for me:\n\ngit config alias.stash '!git diff-files --name-only -z | git update-index \n-z --stdin && tree=$(git-write-tree) && commit=$(echo stash $(date) | \ngit-commit-tree $tree) && git-update-ref refs/heads/stash $commit && \ngit-reset --hard'\n\n(This is one long line.)\n\nWith this, I can now say \"git stash\" with a dirty working directory, and \nit will have the same effect as \"git reset --hard\", i.e. reset to the \nclean state in HEAD.\n\nExcept that all my changes are stashed away in the branch \"stash\". It is \nnot really a branch, as I expect it to jump from loose end to loose end, \nlike this:\n\nA - B - C - D - E - F - G - H - ...  (master branch)\n  \\               \\       \\\n    A'  ..          E'  ..  G'       (stash branch)\n\nThe \"..\" denote reflog connections: \"git log stash\" will show G' and as \nits parent G with its history, while \"git reflog stash\" will show G', and \nthen E', and then A'.\n\nMaybe it is not only useful for me...\n\nCiao,\nDscho\n"},{"id":"44275","messageId":"8c5c35580706071552v3a099fdci1baec9101a40242b@mail.gmail.com","threadId":"8488","inReplyTo":"Pine.LNX.4.64.0706072328000.4046@racer.site","subject":"Re: git-stash","fromName":"Lars Hjemli","fromEmail":"hjemli@gmail.com","sentAt":"2007-06-07T22:52:07Z","receivedAt":"2007-06-07T22:52:07Z","isPatch":false,"sender":{"key":"hjemli@gmail.com","avatar":null},"body":"On 6/8/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> git-commit-tree $tree\n\nI added -p HEAD here, and it's even nicer ;-)\n\nThanks!\n\n--\nlarsh\n"},{"id":"44278","messageId":"Pine.LNX.4.64.0706072354370.4046@racer.site","threadId":"8488","inReplyTo":"8c5c35580706071552v3a099fdci1baec9101a40242b@mail.gmail.com","subject":"Re: git-stash","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-06-07T22:55:02Z","receivedAt":"2007-06-07T22:55:02Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 8 Jun 2007, Lars Hjemli wrote:\n\n> On 6/8/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> > git-commit-tree $tree\n> \n> I added -p HEAD here, and it's even nicer ;-)\n\nYep, you're right. I forgot that in my \"final\" version.\n\nThanks,\nDscho\n"},{"id":"44286","messageId":"8c5c35580706071638m39bccc7xeee6b790c00af993@mail.gmail.com","threadId":"8488","inReplyTo":"Pine.LNX.4.64.0706072328000.4046@racer.site","subject":"Re: git-stash","fromName":"Lars Hjemli","fromEmail":"lh@elementstorage.no","sentAt":"2007-06-07T23:38:38Z","receivedAt":"2007-06-07T23:38:38Z","isPatch":false,"sender":{"key":"lh@elementstorage.no","avatar":null},"body":"On 6/8/07, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> I just was in the need for git-stash (for the 1e6th time this year), but\n> instead of writing a script, I though I'd try the \"!\" convention for\n> aliases.\n\nFwiw, here's a very simple unstash:\n\ngit config alias.unstash '!git diff --binary stash^ stash | git-apply -'\n\n--\nlarsh\n"},{"id":"44294","messageId":"18024.41550.399465.780261@lisa.zopyra.com","threadId":"8488","inReplyTo":"Pine.LNX.4.64.0706072328000.4046@racer.site","subject":"Re: git-stash","fromName":"Bill Lear","fromEmail":"rael@zopyra.com","sentAt":"2007-06-08T00:26:54Z","receivedAt":"2007-06-08T00:26:54Z","isPatch":false,"sender":{"key":"rael@zopyra.com","avatar":"https://gravatar.com/avatar/c4f2d2790ca3828d3b4e7dfebabf61d2fe94fd82fa49cdac2a5295dd2d46a874?d=mp&s=160"},"body":"On Thursday, June 7, 2007 at 23:28:33 (+0100) Johannes Schindelin writes:\n>Hi,\n>\n>I just was in the need for git-stash (for the 1e6th time this year), but \n>instead of writing a script, I though I'd try the \"!\" convention for \n>aliases. Works quite well for me:\n\nExcellent work.  I do this sort of stuff all the time.  I called my\nlame version \"shelf\", but this works for me ...\n\n\nBill\n"},{"id":"44317","messageId":"20070608065245.GA27863@moooo.ath.cx","threadId":"8488","inReplyTo":"Pine.LNX.4.64.0706072328000.4046@racer.site","subject":"Re: git-stash","fromName":"Matthias Lederhofer","fromEmail":"matled@gmx.net","sentAt":"2007-06-08T06:52:45Z","receivedAt":"2007-06-08T06:52:45Z","isPatch":false,"sender":{"key":"matled@gmx.net","avatar":null},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> I just was in the need for git-stash (for the 1e6th time this year), but \n> instead of writing a script, I though I'd try the \"!\" convention for \n> aliases. Works quite well for me:\n\nI have scripts saving and restoring the current state of the working\ntree in the current branch using two commits: one is the current index\nand the other one the index after adding all changes.\n\n% tail -n 1000 save restore\n==> save <==\n#!/bin/sh\nset -e\ndie() { echo \"$0: $*\" >&2; exit 1; }\n\nparent=$(git rev-parse HEAD^0 2> /dev/null) || die requires at least one commit\ntree=$(git write-tree)\ncommit=$(echo wip index | git commit-tree $tree -p $parent)\n\ngit diff-files --name-only -z | git update-index --remove -z --stdin\ntree=$(git write-tree)\ncommit=$(echo wip working tree | git commit-tree $tree -p $commit)\n\ngit update-ref -m 'wip save' HEAD $commit\necho saved wip\n\n==> restore <==\n#!/bin/sh\nset -e\ndie() { echo \"$0: $*\" >&2; exit 1; }\n\np=$(git rev-parse HEAD~1) || die requires at least 3 commits\npp=$(git rev-parse HEAD~2) || die requires at least 3 commits\ngit-read-tree --reset $p\n\ngit update-ref -m 'wip restore' HEAD $pp\necho restored wip\n"}]}