Re: git-stash
- From
- Matthias Lederhofer <matled@gmx.net>
- Date
- Jun 8, 2007, 06:52 UTC
- Message-ID
- <20070608065245.GA27863@moooo.ath.cx>
- In-Reply-To
- <Pine.LNX.4.64.0706072328000.4046@racer.site>
Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> I just was in the need for git-stash (for the 1e6th time this year), but > instead of writing a script, I though I'd try the "!" convention for > aliases. Works quite well for me:
I have scripts saving and restoring the current state of the working tree in the current branch using two commits: one is the current index and the other one the index after adding all changes.
% tail -n 1000 save restore ==> save <== #!/bin/sh set -e die() { echo "$0: $*" >&2; exit 1; }
parent=$(git rev-parse HEAD^0 2> /dev/null) || die requires at least one commit tree=$(git write-tree) commit=$(echo wip index | git commit-tree $tree -p $parent)
git diff-files --name-only -z | git update-index --remove -z --stdin tree=$(git write-tree) commit=$(echo wip working tree | git commit-tree $tree -p $commit)
git update-ref -m 'wip save' HEAD $commit echo saved wip
==> restore <== #!/bin/sh set -e die() { echo "$0: $*" >&2; exit 1; }
p=$(git rev-parse HEAD~1) || die requires at least 3 commits pp=$(git rev-parse HEAD~2) || die requires at least 3 commits git-read-tree --reset $p
git update-ref -m 'wip restore' HEAD $pp echo restored wip