Hacker News new | ask | show | jobs
by __david__ 5263 days ago
A small nit about git stashes: they aren't stored in a special linear branch. Each stash is a little branch off of wherever you were when you created the stash. The only trick is that the stash commits are named something weird so that "git stash list" can find them and list them.

You can check this yourself:

    git show stash@{0}
Look where it says "WIP on {branch-name}: {hash}". That {hash} will be one of the hashes in the "Merge" header near the top of the commit.

You can also see this visually with "gitk --all".

1 comments

You are correct. They aren't a linear history. In fact, the key is the @{#} syntax (man git-rev-parse). Each stash commit is a single commit pointed to by a ref/stash reference. Because of the reflog, we can see what ref/stash used to point at, that is @{1}, @{2}, etc.
It's actually (potentially) more than a single commit. If you have a dirty index when you stash then that will also be committed along with your working directory changes. If you use the new(ish) --include-untracked option to stash, a 3rd commit will be added that has the untracked files in it. The main stash commit (that holds your working directory changes) is a fake merge of all the commits, just so there are pointers back to the other 2 commits.