On Tue, 26 Jan 2016 06:56:27 +0100
Pablo Rodríguez <oi...@web.de> wrote:

> I’m a git newbie and I wanted to stash a git repository containing
> text files. There were some uncommited changes in some files.
> I stashed with "git stash".
> I corrected the two typos, committed with "git commit -p" and pushed
> changes to GitHub with "git push origin master".
> Since this was my first stash, I dropped the stash without having
> applied it first (I didn’t know that I had to apply it).

Didn't the word "drop" ring any bells for you? ;-)
To drop is to get rid of, throw away etc.

> I checked out ("git checkout") and I don’t have my uncommited changes
> back. (I went into kernel-panic mode ;-).)

The plain `git checkout` command (without speficying paths explicitly)
is for switching branches.  It tries to preserve any uncommitted
changes while doing so but uncommitted changes are changes you have in
your work tree--that is, on your filesystem--compared to the commit
your work tree and the index are based on.

The stash is orthogonal to all of these: stash entries to not "belong"
to any branch.  The stash is a completely separate entry, and you're
free to apply any stash entry to any state of your work tree and the
index (how successfully that will be depends on how much they differ,
of course).

> How can I apply the dropped commit and get the repo as it was before
> the stash?
> The list is the following:
> $ git stash list
> stash@{0}: WIP on master: ec7ebb0 added class signature-author added
> class none to description list
> $ git stash drop
> Dropped refs/stash@{0} (7113eadaa3750ab12db0652e139d37f01700d71d)
> Searching for a solution, I found
> http://incorrectcode.news/question/508/how-to-recover-a-dropped-stash-in-git/.
> The above source isn’t perfectly clear to me. Is the following command
> the right way to recover the repo status previous to stash?
>    git stash apply 7113eadaa3750ab12db0652e139d37f01700d71d

Yes, that should work.

For the future, note that in normal (non-bare) Git repositories by
default all "drastic head movements" are recorded in the so-called
"reflog" which can be examined/controlled via the `git reflog` command.
Branch deletions / forced updates (say via `git reset --hard` or
`git branch -M`) are all recorded there.  Stash drops too.  This is a
"safety belt" intended for recovering from occasional "oopsies" like

All-in-all, I'd recommend to read a book on Git ([1] will be OK) to get
a good overview of what Git can offer to you.

1. http://git-scm.com/book

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to