What are the semantics of `git reset stash`?

Viewed 41

Today, I accidentally typed the command git reset stash and it did some very strange things to my recent history. It looks like at minimal, it removed the most recent commit, and added two other commits, one for the index and one for the stash itself.

I looked around man git-reset but did not find this behavior described there.

What is the intended semantic of this command, and is it documented somewhere?

1 Answers

stash is recognized by git as a reference to the commit that contains the most recent stash - try git rev-parse stash or cat .git/refs/stash, which will print a commit SHA.

So git reset stash simply had the same effect as any git reset <branch/tag/commit>: it reset your current branch to point to the commit you indicated, and leaves any differences between the original and new commit as pending changes. (And stashes are made up of two commits, which as you say contain the index and the workdir changes.)

Related