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?
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.
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 .
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With