Last night, I read a trick in a good article, Git from the bottom up, by John Wiegley, that I tried out this morning.
git stash stashes away the current state of your world (the index), and replaces it with the HEAD. git stash apply restores the stash. The pair snapshots your work, but leaves it unchanged.
I now run this command as an hourly cron job:
#!/bin/bashHere's the crontab entry:
# snapshot the current repository
git stash
git stash apply
The snapshots, however, are all accessible through the reflogs, which means that my states are stashed, hourly, invisibly to me, but I can get them back pretty easily.# | hour (0-23)
# | | day of the month (1-31)
# | | | month of the year (jan-dec)
# | | | | day of the week (sun-mon, with 0=sun)
# | | | | | command
# | | | | | |
#
01 * * * * ~/bin/snapshot &> /dev/null
If there have been no changes, git stash notices, and does nothing, so the hourly job doesn't fill my logs with irrelevant entries.
Very nice.
1 comment:
Great readiing this
Post a Comment