Is it possible to have more than just one backup when editing text files?

There is a simple way to use mercurial for version control. First install it.

To configure mercurial make a file ~/.hgrc with next content:

[ui]
username = Your name <your mail>
verbose = True

If you use some mercurial servers, you can add more info to this file (read man hgrc).

After that cd to directory with your text files. For example:

> cd /tmp
> mkdir data && cd data
> cat > text_file.txt
Hello, this is a file.

You can add also any number of files. After we must init mercurial:

> hg init

By default there's no files still, so we must to say mercurial, that we want to include all:

> hg st
? text_file.txt
> hg add    
adding text_file.txt
> hg st
A text_file.txt

Now we make do simple commit:

> hg comm -m 'first run'
text_file.txt
committed changeset 0:87e90c949984

Now do some fixes and see difference:

> cat >> text_file.txt 
Add one line.
> hg diff
diff -r 87e90c949984 text_file.txt
--- a/text_file.txt Mon Apr 01 12:52:14 2013 +0400
+++ b/text_file.txt Mon Apr 01 12:53:47 2013 +0400
@@ -1,1 +1,2 @@
 Hello, this is a file.
+Add one line.

Now make another commit, after watch hg log: you will see both commits.

To return to first commit just do so:

> hg upd -r 0:87e90c949984
resolving manifests
getting text_file.txt
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
> cat text_file.txt 
Hello, this is a file.

You see: a file is old.

Now restore last file:

> hg upd                  
resolving manifests
getting text_file.txt
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
> cat text_file.txt 
Hello, this is a file.
Add one line.

Also you may do a simple script:

#!/bin/bash
while true; do
  hg commit -m "commit: $(date)"
  sleep 60
done

Run it when you start to edit your file, and it will check for changes every minute, if there was changes, mercurial will make new commit. Also, as I've mention in comments, you can use at or cron for autocommits.

Tags:

Backup

Editors