Skip to content

Instantly share code, notes, and snippets.

@weshouman
Last active October 28, 2017 06:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weshouman/11283929 to your computer and use it in GitHub Desktop.
Save weshouman/11283929 to your computer and use it in GitHub Desktop.
git stash saver! #vcs
#!/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