Last Updated: February 25, 2016
·
19.52K
· dsci

Git: Reverse a stash apply

Sometimes I want to undo a git stash apply.

git stash show -p | git apply --reverse

That combines:

Show the changes recorded in the stash as a diff between the stashed state and its original parent. When no <stash> is given, shows the latest one. By default, the command shows
the diffstat, but it will accept any format known to git diff (e.g., git stash show -p stash@{1} to view the second most recent stash in patch form).

(Extracted from git-stash man page)

and

-R, --reverse
Apply the patch in reverse.

(Extracted from git-apply man page)