Take control over configuration files and store them in version control system using etckeeper utility created by Joey Hess,
which seamlessly integrates with package management tools inside Debian operating system.


Use the following command to install etckeeper utility.

$ sudo apt-get install etckeeper

Configuration is stored inside /etc/etckeeper directory.

By default configuration files inside /etc directory are stored using git repository.


Initialize repository

Repository inside /etc is initialized and committed after etckeeper installation,
use the the following command to repeat first step.

$ sudo etckeeper init

Repository will be only initialized, nothing will be committed. In any case the existing repository will be not overwritten.

Delete repository

Delete etckeeper repository inside /etc directory.

$ sudo etckeeper uninit
** Warning: This will DESTROY all recorded history for /etc,
** including the git repository.
Are you sure you want to do this? [yN] y

Commit changes

Commit all changes inside /etc directory.

$ sudo etckeeper commit "modified motd file"
[master 24bca01] modified motd file
 Author: milosz <milosz@xmail.sleeplessbeastie.eu>
 1 file changed, 1 insertion(+)

List changes

List modified, created or deleted files.

$ sudo etckeeper vcs status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#	modified:   motd
no changes added to commit (use "git add" and/or "git commit -a")

Reset changes

Reset all modifications.

$ sudo etckeeper vcs reset --hard
HEAD is now at 24bca01 modified motd file

List log entries

Show commit logs.

$ sudo etckeeper vcs log
commit 24bca015d8bad77eaa85bef6988ab2d94928562e
Author: milosz <milosz@xmail.sleeplessbeastie.eu>
Date:   Sat Nov 1 23:11:12 2014 +0000
    modified motd file
commit 0ea331237044537e8ebc95020352f60fef068546
Author: milosz <milosz@xmail.sleeplessbeastie.eu>
Date:   Sat Nov 1 23:10:46 2014 +0000
    Initial commit

Recover older version of specified file

Checkout file from specified revision.

$ sudo etckeeper vcs checkout 0ea331 motd

View differences

Show applied but not committed changes.

$ sudo etckeeper vcs diff
diff --git a/motd b/motd
index 2d3a0a3..6c21842 100644
--- a/motd
+++ b/motd
@@ -3,6 +3,3 @@ The programs included with the Debian GNU/Linux system are free
 the exact distribution terms for each program are described in the
 individual files in /usr/share/doc/*/copyright.
-Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
-permitted by applicable law.

Check if there are uncommitted changes

The following command will return true if there are uncommitted changes.

$ sudo etckeeper unclean
$ if [ "$?" -eq "0" ]; then echo "uncommitted changes"; else echo "no uncommitted changes"; fi
uncommitted changes

Additional notes

You are not tied to the /etc directory, as you can always use -d parameter to specify different directory.

Uncommitted changes are committed daily (see /etc/cron.daily/etckeeper file), use AVOID_DAILY_AUTOCOMMITS configuration directive to alter this behavior.