Last active
October 28, 2017 06:48
-
-
Save weshouman/11283929 to your computer and use it in GitHub Desktop.
git stash saver! #vcs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This may not be the best -or even a good- practice! but it works well for my requirements, and that has no guarantees it should work well in all cases | |
# Stashes are OVERWRITTEN, so if u had anything named stash[0-9]+.diff it will be OVERWRITTEN, this was an intended behavior for my case, no checks are provided :-| | |
# No Warranties at all, just have your backups available ^_^ | |
# This code is more focused on trying different shell scripting operations | |
git stash list > ./stash_list_temp | |
# to assign use equal directly after the variable name | |
# to get the RHS assigned from a script use $(script) and ensure no spaces between the = and the $ | |
ST_NO=$(wc -l stash_list_temp | tr -cd 0-9) | |
# Variable printing | |
echo $ST_NO | |
echo "number of stashes is $ST_NO" | |
# Assign a new value to the variable | |
# Works with #!/bin/bash but not with #!/bin/sh | |
let "ST_NO -= 1" | |
## Do arith operations on variables | |
#echo "number of stashes is $(ST_NO + 1)" | |
# For loop | |
for i in $(seq 0 $ST_NO) | |
do | |
#that could be optimized to name the scripts directly to the stashes! | |
#but this is another version :D | |
STASHNAME="stash$i.diff" | |
git stash show -p stash@{"$i"} > $STASHNAME | |
echo "stashed into $STASHNAME" | |
done | |
## Sequence Creation | |
#a=$(seq 1 4) | |
#echo $a | |
#TODO sanity checks (ie: stashes are available or not!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment