Git How To: Undo/Revert a saved stash by Message easily

让人想犯罪 __ 提交于 2020-02-05 06:06:29

问题


Problem with git current commands:

  1. Can't easily apply by a saved Stash by Message (message is a secondary param to track stashes more easily rather than index only)
  2. Can't remove specific Stash by Message

Example: Must apply and revert via Stash's index.

git stash push -m "Dev_Configs"
git stash list                            // < Find index. 
git stash apply 0

And unapply "all" (not specific based on stash)

git stash show -p  | git apply -R

回答1:


git version 2.25.0.windows.1

"HardCoded" WAY

  1. Save

    git stash push -m "devConfigs"
    
  2. Setup Alias's: (in this example "stash-apply-devConfigs", "stash-unapply-devConfigs")

    git config --global alias.stash-apply-devConfigs '!git stash apply $(git stash list | grep "devConfigs" | cut -d: -f1)'
    git config --global alias.stash-unapply-devConfigs '!git stash show $(git stash list | grep "devConfigs" | cut -d: -f1) -p | git apply -R'
    
  3. Usage

    git stash-apply-devConfigs
    git stash-unapply-devConfigs
    

"Via Parameter"

  1. Save

    git stash push -m "devConfigs"
    
  2. Setup Function Alias's

    git config --global alias.stash-a '!f() { git stash apply $(git stash list | grep $1 | cut -d: -f1); }; f'
    

    Setup Alias: Un-apply Stash by Name

    git config --global alias.stash-u '!f() { git stash show $(git stash list | grep $1 | cut -d: -f1) -p | git apply -R; }; f'
    
  3. Usage:

    git stash push -m "easyName"
    git stash-a easyName
    git stash-u easyName
    


来源:https://stackoverflow.com/questions/59973103/git-how-to-undo-revert-a-saved-stash-by-message-easily

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!