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

git-stash

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jun 7, 2007, 22:28 UTC
Message-ID
<Pine.LNX.4.64.0706072328000.4046@racer.site>
Hi,

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:

git config alias.stash '!git diff-files --name-only -z | git update-index -z --stdin && tree=$(git-write-tree) && commit=$(echo stash $(date) | git-commit-tree $tree) && git-update-ref refs/heads/stash $commit && git-reset --hard'

(This is one long line.)

With this, I can now say "git stash" with a dirty working directory, and it will have the same effect as "git reset --hard", i.e. reset to the clean state in HEAD.

Except that all my changes are stashed away in the branch "stash". It is not really a branch, as I expect it to jump from loose end to loose end, like this:

A - B - C - D - E - F - G - H - ...  (master branch)
  \               \       \
    A'  ..          E'  ..  G'       (stash branch)

The ".." denote reflog connections: "git log stash" will show G' and as its parent G with its history, while "git reflog stash" will show G', and then E', and then A'.

Maybe it is not only useful for me...

Ciao, Dscho

Next: Lars Hjemli
Message 1 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.