How to reverse apply a stash?

前端 未结 11 2192
忘掉有多难
忘掉有多难 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:35

    This is in addition to the above answers but adds search for the git stash based on the message as the stash number can change when new stashes are saved. I have written a couple of bash functions:

    apply(){
      if [ "$1" ]; then
        git stash apply `git stash list | grep -oPm1 "(.*)(?=:.*:.*$1.*)"`
      fi
    }
    remove(){
      if [ "$1" ]; then
        git stash show -p `git stash list | grep -oPm1 "(.*)(?=:.*:.*$1.*)"` | git apply -R
        git status
      fi
    }
    
    1. Create stash with name (message) $ git stash save "my stash"
    2. To appply named $ apply "my stash"
    3. To remove named stash $ remove "my stash"

提交回复
热议问题