问题
Problem with git current commands:
- Can't easily apply by a saved Stash by Message (message is a secondary param to track stashes more easily rather than index only)
- 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
Save
git stash push -m "devConfigs"
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'
Usage
git stash-apply-devConfigs git stash-unapply-devConfigs
"Via Parameter"
Save
git stash push -m "devConfigs"
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'
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