How to reverse apply a stash?

前端 未结 11 2197
忘掉有多难
忘掉有多难 2020-11-29 14:32

I have a small patch saved away in my git stash. I\'ve applied it to my working copy using git stash apply. Now, I\'d like to back out those changes by revers

11条回答
  •  伪装坚强ぢ
    2020-11-29 15:33

    The V1 git man page had a reference about un-applying a stash. The excerpt is below.

    The newer V2 git man page doesn't include any reference to un-applying a stash but the below still works well

    Un-applying a Stash In some use case scenarios you might want to apply stashed changes, do some work, but then un-apply those changes that originally came from the stash. Git does not provide such a stash un-apply command, but it is possible to achieve the effect by simply retrieving the patch associated with a stash and applying it in reverse:

    $ git stash show -p stash@{0} | git apply -R
    

    Again, if you don’t specify a stash, Git assumes the most recent stash:

    $ git stash show -p | git apply -R
    

    You may want to create an alias and effectively add a stash-unapply command to your Git. For example:

    $ git config --global alias.stash-unapply '!git stash show -p | git apply -R'
    $ git stash apply
    $ #... work work work
    $ git stash-unapply
    

提交回复
热议问题