Is there a tool that automatically saves incremental changes to files while coding?
One of my favorite features of Google docs is the fact that it's constantl开发者_Go百科y automatically saving versions of my document as I work. This means that even if I forget to save at a certain point before making a critical change there's a good chance that a save point has been created automatically. At the very least, I can return the document to a state prior to the mistaken change and continue working from that point.
Is there a tool with an equivalent feature for a Ruby coder running on Mac OS (or UNIX)?
For example, a tool that will do an automatic Git check-in every couple of minutes to my local repository for the files I'm working on. Maybe I'm paranoid, but this small bit of insurance could put my mind at ease during my day-to-day work.
VIM
Some may hate my response to this, but I use VIM quite often when coding and it has an auto-save feature, albeit an auto-save to a swap file. It is also extensible so that automatic commits can be done.
To see how extensible VIM is, check out this post: How can I script vim to run perltidy on a buffer?
The Netbeans IDE has a local history, which is enabled by default. Each time you save the file (ctrl-s), an entry is added to the file's history. As for the other supported VCSs, you can browse the history, see the diffs, and revert to a previous state.
Plus, Netbeans is known for having a really good support for Ruby developpment.
RubyMine automatically saves as you type and automatically saves a history of local changes. As far as I know, it won't automatically commit to Git, but it does integrate with Git. RubyMine works quite well on Mac OS X.
If you go down this “autocommit” road, always be sure to keep such history local. As Russell Steen commented, automatic checkpoints are not something that belongs in any kind of published, advertised branch. It is fine to keep for local reference, but otherwise it is just an ungroomed mess unfit for publication.
It is not too hard to write a simple script that will ‘autocommit’ to an specified branch. The linked script is not one that I use, just one that I found. It is a bit ugly in that it forcibly changes branches, so you would have to make sure it does not run if you are doing stuff manually. Also, it uses ‘porcelain’ Git commands instead of sticking to the lower-level (but correspondingly, more interface-stable) ‘plumbing’ commands.
You might also be interested enough to review a recent thread on the Git mailing list that covered some of this ground.
In particular, it references another script that does not “steal the current branch” and does a better job of using plumbing commands (but inexplicably, still uses git add
instead of git ls-files
and git update-index
).
All in all, writing a script to do what you want is not terribly difficult. Doing it right (using plumbing, not stomping on the active branch (which is easy when you using plumbing), etc.) is a bit more effort, but worth it for the bits of Git that you will learn along the way.
You could even use the old shell implementation of git-commit
as a starting point (and a good example of the plumbing and how to use it).
To get a checkpoint on a regular basis, just a stick script like ones of these it in a crontab.
Also Vim :) But what I use is much different from what kzh wrote.
I don't use a version control system for my automatic backup files, I rather
want to see all versions of all files in my ~/vim_backup
directory. (Note:
of course I do use git for version controlling my source files, but now we are
talking about automatic backups.) The following lines in my .vimrc will make
Vim create a backup file each time the file is saved. The name of the backup
file is the name of the normal file plus the current date and time.
The following lines are in my .vimrc file:
if v:version >= 700
" If I have a ~/vim_backup directory, let that be the backup "
" directory; otherwise do not back up. "
" (Vim version earlier than 7.0 do not have the finddir function.) "
if finddir("~/vim_backup") != ""
set bdir=~/vim_backup/
set backup
else
set nobackup
endif
endif
" We set the 'backupext' option to contain the current date and time, so "
" that the name of the backup file will be the concatenation of the name "
" of the normal file and the current date and time. "
function! HRefreshBackup()
execute ":set backupext=" . strftime(".%y%m%d_%H%M")
" You may want to have %H%M%S instead of %H%M if you want to have the "
" possibility of having multiple backups in a minute. "
endfunction
" Refresh the backup file name before each "save" "
au BufWritePre * call HRefreshBackup()
Example of how my ~/vim_backup
directory looks like:
$ ls -ltr ~/vim_backup | head
total 105692
-rwx--x--x 1 hcs hcs 252 2009-12-19 06:49 Sync_flash.091222_0902
-rwxr-xr-x 1 hcs hcs 819 2009-12-19 06:49 hk.091229_1637
-rwxr-xr-x 1 hcs hcs 507 2009-12-19 06:49 FOLLOW_LINK.091220_0802
-rwx--x--x 1 hcs hcs 212 2009-12-19 06:49 Cut.091230_2113
-rwxr-xr-x 1 hcs hcs 275320 2009-12-19 06:51 margitka.100116_1949
-rw-r--r-- 1 hcs hcs 80 2009-12-19 06:51 localrc_dorsu.vim.100101_1112
-rwx--x--x 1 hcs hcs 10335 2009-12-19 06:51 Video.091222_1754
-rwxr-xr-x 1 hcs hcs 1255 2009-12-19 06:51 Update.091222_1754
-rwxr-xr-x 1 hcs hcs 716 2009-12-19 06:51 SshMaker.091222_1754
This wastes some disk space, since all versions of all files are stored . So it may be worth to periodically archive and compress them. I tried several tools to compress the set of backup files, and "rar" with the "-s" option was the best. 100 megabytes of backup files were created in the last three month, and "rar -s" compressed it to 3 MB.
I use the Eclipse IDE for several languages and for all projects which do not have a GUI. One nice bonus is a local history and the ability to compare the current version with any previous version, either completely replacing the current version with any given previous version, or copying across some changes and ignoring others.
Have a look at this for using Ruby in Eclipse - http://www.ibm.com/developerworks/opensource/library/os-rubyeclipse/
精彩评论