Javdev22
Javdev22

Reputation: 31

Recover untracked files after doing git stash --include-untracked

So basically I needed to checkout an old commit in order to see how the application was behaving back then. The thing is, when I did "git checkout", for some reason Git asked me to do something with the untracked files first and after googling, I saw "git stash --include-untracked".

The problem is, after doing this, I have now lost all my work. I tried to go back to my lastest branch/commit, but the whole configuration in Intellij Idea is messed up.

Is there anyway I can UNDO all of this and go back to where I was before I screwed up?

I have tried a lot of different answers, like git reflog, git reset, git stash apply, but nothing helps. I am desperate.

Upvotes: 2

Views: 607

Answers (1)

LeGEC
LeGEC

Reputation: 51790

Run git log --oneline --graph stash, you should have a clear enough view of how the commits created by git stash are related one to another.

You will also see that your content is not lost (it is somehow stored in git).


When you run git stash --include-untracked, git creates a stash where the untracked content is accessible at stash^2.

To restore the .idea/ directory, for example, just run :

git restore -s stash^2 -W -- .idea/

To completely undo your git stash action, the safest way is to come back to the commit you stashed from and run git stash pop :

git checkout <the/previous/branch>
# or use the following shortcut :
git checkout -

git stash pop

Upvotes: 1

Related Questions