Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a better way of doing a git stash pop and then discard the stashed changes if I don't merge?

Tags:

git

Sometimes I git pop and get things I don't want to merge and want to throw away. Is there a better way throwing away that stash than what I'm currently doing:

git stash pop

Decide I don't want the stash.

git reset HEAD
git checkout -- .
git stash drop

If I pop but don't merge the stash stays, which is why I drop it.

like image 216
Kit Sunde Avatar asked Jan 17 '23 11:01

Kit Sunde


1 Answers

You don't have to do the git reset HEAD and git checkout -- etc ( which in itself is verbose, as you can just do git reset --hard to get a clean working directory) to drop a stash. You just have to do git stash drop and the stash will be dropped. Note that when you pop and git can't apply cleanly, the stash is not popped and is still there. You are then dropping it after cleaning up, which is not necessary.

You might also want to use the branch option of git stash if you are facing lots of conflicts. It will create a new branch off the HEAD where you stashed.

like image 93
manojlds Avatar answered Jan 27 '23 05:01

manojlds