I did a git stash pop and now I have a ton of conflicts. I had committed all my recent code before the git stash pop
, so is there a way to go back to the last commit and get rid of all the conflicts and code the git stash pop
injected?
-
1Do you still want the popped work saved, or do you never want to see it again? – jscs Nov 18 '13 at 00:27
-
2No I don't want the Popped work. I did the stash like 4 months ago and not sure what is even in there? – jdog Nov 18 '13 at 00:28
-
2Do you care about things that were uncommitted before stashing? – Andrew Marshall Nov 18 '13 at 00:37
-
The ones 4 months ago or the ones today? I want what I had a hour ago. – jdog Nov 18 '13 at 00:39
-
possible duplicate of [Revert to previous Git commit](http://stackoverflow.com/questions/4114095/revert-to-previous-git-commit) – simont Nov 18 '13 at 02:39
-
7If there are conflicts when you `git stash` then git will not drop the stash from the list. So `git reset --hard HEAD` does not destroy the popped work. – jwadsack Apr 22 '14 at 04:27
3 Answers
This has already been asked and answered on stackoverflow (see How to revert Git repository to a previous commit?), but the simple answer is:
git reset --hard HEAD
This should take care of your problem. Note that this removes all uncommitted changes from the repository.
Note that if there are conflicts, the stash is preserved. From the stash docs:
Applying the state can fail with conflicts; in this case, it is not removed from the stash list. You need to resolve the conflicts by hand and call
git stash drop
manually afterwards.

- 1
- 1

- 3,024
- 1
- 16
- 25
-
Ok but is this going to pull from my local version of git or the one on GitHub. Because for some reason my git pushes have not been landing on Github (see here http://stackoverflow.com/questions/20037823/git-push-not-pushing-to-github?noredirect=1#comment29842387_20037823) – jdog Nov 18 '13 at 00:34
-
1This will revert your local repo to the last commit. You should be able to push all of your commits (since the last push) without issue. If it does not work, then post the results back to your previous question). Good luck. – MichaelMilom Nov 18 '13 at 00:41
-
31
-
23@K.Weber if `git stash pop` resulting in conflict, the stash won't be deleted from stash list. – Daiwei Jan 21 '16 at 22:09
-
3I'm not sure who's upvoting the 'actually you won't lose your stash', I just lost mine – Anthony Jan 17 '17 at 18:58
-
6Not much of a solution imho, since it points out that you _will_ lose uncommited changes. – Ivan P Apr 05 '17 at 17:05
-
1
-
1you don't lost the stash if you make git show hash and put the hash you can see it and if you do git merge hash you can merge it again – Emiliano Jan 21 '19 at 19:28
-
Reset can also be called on specific files :
git reset HEAD <filename>...
You can't hard reset a file though. But you can revert the changes with checkout afterwards :
git checkout -- <filename>...
You stash will be preserved, as pointed out by Luke in MichaelMilom answer.
This is useful when you don't want to lose your un-committed local changes.

- 103
- 1
- 7
If you never want to see the work in the popped stash again, this is as simple as a hard reset:
git reset --hard HEAD
This tells git to ignore the fact that you have uncommitted changes in your working directory, and sets the working directory, the staging area, and head to the commit you specify -- in this case, the existing HEAD, that contains all the work you've just committed.

- 63,694
- 13
- 151
- 195