Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the semantics of `git reset stash`?

Tags:

git

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?

like image 758
merlin2011 Avatar asked Jun 29 '20 23:06

merlin2011


People also ask

What does git reset do?

To review, git reset is a powerful command that is used to undo local changes to the state of a Git repo. Git reset operates on "The Three Trees of Git". These trees are the Commit History ( HEAD ), the Staging Index, and the Working Directory.

Does git reset affect stash?

No, git reset --hard origin/master does not affect your stashes in any way. Show activity on this post. The hard reset command you showed above would move the HEAD pointer of whatever the current branch might be to origin/master , but it would not affect the stash commits, which are stored in . git/refs/stash .


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.)

like image 155
Aasmund Eldhuset Avatar answered Oct 19 '22 21:10

Aasmund Eldhuset