git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-stash

From
MLMatthias 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

Previous: Bill Lear
Message 6 of 6 in “git-stash”
  1. Johannes SchindelinJun 7, 2007
  2. Lars HjemliJun 7, 2007
  3. Johannes SchindelinJun 7, 2007
  4. Lars HjemliJun 7, 2007
  5. Bill LearJun 8, 2007
  6. Matthias LederhoferJun 8, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.