Automatically stashing
Posted
by Readonly
on Stack Overflow
See other posts from Stack Overflow
or by Readonly
Published on 2008-11-17T21:18:49Z
Indexed on
2010/03/13
1:27 UTC
Read the original article
Hit count: 454
git
|version-control
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:
- If there are no changes to your working copy, the "git stash apply" will cause your last stash to be applied over your working copy.
- There could be race conditions between when the cron job executes and the user working on the working copy. For example, "git stash" runs, then the user opens the file, then the script's "git stash apply" is executed.
Does anybody have suggestions for making this automatic stashing work more reliably?
© Stack Overflow or respective owner