If the harm is already done, here's a command line way of getting back the official version of the configuration file. First, download the package file (either with apt-get --download-only as below, or from the package page on packages.ubuntu.com), then extract its contents in a temporary location. You can then copy the file into /etc. Make sure to respect the original permissions (most files in /etc are owned by root and mode 644 (i.e. word-readable and root-writable), but each exception is there for an important reason).
sudo apt-get --download-only --reinstall install foo
mkdir /tmp/foo
dpkg-deb -x /var/cache/apt/archives/foo_VERSION_ARCH.deb /tmp/foo
Note that this doesn't apply to the configuration files that are not from a package, such as /etc/fstab or /etc/passwd. If you lose these, you're on your own. (Most are very system-dependent anyway.)
For the future, I recommend using etckeeper
. Install the package and run sudo etckeeper init. This sets up version control for all files in /etc. You don't need to do anything else to manage etckeeper; you only need to interact with it when you want to do a version control operation, such as referring to older files. Files are automatically committed before and after each run of apt and every night (this is configurable).
By default, on Ubuntu, etckeeper uses Bazaar. Change the setting in /etc/etckeeper/etckeeper.conf before running etckeeper init if you prefer Darcs, Git or Mercury.
With Bazaar, to revert /etc/foo.conf to the last committed version:
cd /etc
sudo bzr revert foo.conf
If you want to go back further in time, use sudo bzr log foo.conf to view the history of the file, and sudo bzr revert -r 42 foo.conf if you've determined that revno: 42 is the revision you want to revert to.
foo, what ifbardepends onfooand I don't want to removebar? – Ryan Thompson Nov 12 '10 at 16:52