The section Last links in the chain: Stashing and the reflog in http://ftp.newartisans.com/pub/git.from.bottom.up.pdf recommends stashing often to take snapshots of your work in progress. The author goes as far as recommending that you can use a cron job to stash your work regularly, without having to do a stash manually.
The beauty of stash is that it lets you apply unobtrusive version control to your working process itself: namely, the various stages of your working tree from day to day. You can even use stash on a regular basis if you like, with something like the following snapshot script:
$ cat <<EOF > /usr/local/bin/git-snapshot #!/bin/sh git stash && git stash apply EOF $ chmod +x $_ $ git snapshot
There’s no reason you couldn’t run this from a cron job every hour, along with running the reflog expire command every week or month.
The problem with this approach is:
Does anybody have suggestions for making this automatic stashing work more reliably?
Auto-Stash is a suite of money-saving tools that allows users to save and invest automatically, and we at Stash think they are a few of our most important financial tools. Auto-Stash takes the weight off your shoulders by putting your savings on autopilot—it will invest your money, and you won't have to lift a finger.
To adjust Set Schedule on the app: To change the amount Go to Auto-Stash (tab on iOS, menu item on Android) Select Set Schedule Choose your portfolio Tap the investment you want to change Enter the amount you want to set Select Save to confirm your change To change the frequency Go to Auto-Stash (tab on iOS,…
Enroll in Round-Ups, and every time you spend with the debit card associated with your linked checking account, Stash will round up your purchase to the nearest dollar. For example, if you spend $10.50, we'll automatically round up your purchase by $. 50.
Stash offers access to a banking account with no overdraft fees or minimum balance through Green Dot Bank. It lets you save automatically using roundups and auto-invest, and it also lets you set goals by separating your cash into spaces for specific purposes.
I certainly wouldn't set up automatic stashing as described in that (otherwise excellent) article, for exactly the reasons you cite.
I prefer to use the stash as it is intended to be used, where I deliberately stash and apply changes as I'm working. For periodic backups, I use a proper backup solution. In my opinion, Git is not a substitute for a backup solution.
git stash is actually just a little shell script that creates a commit which is not referenced in any branch. You could emulate this behaviour without race conditions:
#!/bin/sh
GIT_DIR=$(git rev-parse --git-dir) || exit
ref_stash=refs/stash
w_commit=$(git stash create) # creates a commit for the wip
# gather some info
head=$(git log --no-color --abbrev-commit --pretty=oneline -n 1 HEAD --)
branch=$(git symbolic-ref -q HEAD)
branch=${branch#refs/heads/}
msg=$(printf 'WIP on %s: %s' "$branch" "$head")
# Make sure the reflog for stash is kept.
: >>"$GIT_DIR/logs/$ref_stash"
git update-ref -m "$msg" $ref_stash $w_commit
The script may need some polishing but I hope you get the idea :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With