Home > front end >  Git Stash - Local Changes - Git Stash - Git Stash Apply - Undo
Git Stash - Local Changes - Git Stash - Git Stash Apply - Undo

Time:06-27

Need some help, I screwed up. Please reserve judgement.

Alright, this is what I did.

  1. git stash

  2. made some changes to the code.

  3. git stash (again)

  4. git stash apply

Is there any way I can get back to the code I had before the first git stash.

Any help would be appreciated.

Thanks, in advance.

CodePudding user response:

Appreciate that applying or popping a Git stash just alters the working directory and/or stage. It does not make a new commit. Therefore, simply doing a hard reset should get you back to where you were before the first stash:

# from your branch
git reset --hard

That being said, if you wanted to retain some permutation of the changes since the first stash, that is another story and would require more work and thought to pull off.

Note: Generally speaking, popping a Git stash is risky, because if something goes wrong along the way, you can't reapply the same stash as it has already been popped from the stack. Use git stash apply for best results.

CodePudding user response:

git stash list
<shows all the saved stashes>

git stash show 'stash{0}'
<displays changes in this stash>
<change index according to the one you want, 0 is the last saved stash>

git stash apply 'stash{0}'
<applies the stash>
  • Related