Document revision control systems or version control systems, as they are sometimes called, are used for the management of changes to documents. These systems get more and more important these days as modern work often connects people from around the globe to collaborate and work together on all kinds of documents (for example, software source code) making it important to manage the file changes by different people using revisions. In this recipe, we will show you how to use modern version control systems such as GIT and Subversion to manage the versioning of config files.
To complete this recipe, you will require a working installation of the CentOS 7 operating system with root privileges, and a connection to the Internet in order to facilitate the download of additional packages.
Here in this recipe, we will put the complete main Linux configuration directory, /etc/
, under version control of a Git repository to keep track of all our changes to configuration files:
your_username
and your_email_address
with real names):yum install git git config --global user.email "your_email_address" git config --global user.name "your_username"
/etc
directory:cd /etc/ git init
/etc/
directory under version control:git add *
git commit -a -m "inital commit of the full /etc/ directory"
echo "FILE HAS CHANGED" >> yum.conf
git status
git commit -a -m "changing yum.conf files"
git log --pretty=oneline --abbrev-commit
8069c4a changing yum.conf 5f0d50a inital commit of the full /etc directory
git diff 8069c4a 5f0d50a
git checkout 5f0d50a
Here, in this recipe, we showed you how to use Git to manage changes to system config files in the /etc
directory. This can be important, for example, if you are testing things out, so a lot of changes will be made to some configuration files and you will want to keep track of your changes, which is nice because you don't need to memorize every single step you have taken if you later have to revert the changes or go back to a specific revision, or compare different file versions.
So, what did we learn from this experience?
We started by installing Git and added a username and an e-mail address to its configuration, which is essential for using it later in the process. Then, we changed to the /etc
directory and initialized (using the init
parameter) a new empty Git project there, which is called repository and keeps track of all the files associated to it. This command will add a hidden .git
directory to it, which will contain the complete file changes and revision information. Next, we added all the files (using the wildcard *
operator) from this directory, including all sub-directories to the next revision. A revision is like a state the files are in at a given time point, and is identified by a unique hash ID such as 8069c4a
. Then, we actually created a new revision using the commit parameter and supplied a meaningful message using the -m
parameter. After we set up the Git repository and added all the files to it, every change to the files gets watched in the /etc
directory. Next, we changed the main YUM configuration file in our repository by adding a random string to the end of it using the echo >>
command. If we now use git's status
parameter again, we see in the output that the Git system has notified that this file has been changed. We can now create a new revision with the changed file by using git's commit
parameter again, using another meaningful message here stating that yum.conf
has been changed. We then used the git log
command. This will show us all the committed revisions with their unique md5
hash string IDs. With this ID, we can fuel the git diff
command to see all the file changes between two revisions. To learn more about the output format, use man git-diff-files
and read its section COMBINED DIFF FORMAT
. In our last step, we used the checkout command to go to a specific file revision; here we reverted all our changes and went back to the original file state.
Git is a very powerful version management tool, and in this recipe we just scratched the surface of what can be done with it. To learn more about Git's wonderful techniques, such as branching, merging, pull requests, and so on, start with the Git tutorial pages by typing in man gittutorial
.
You can also use the program Subversion to bring your /etc
directory under version control. Subversion is another common document revision control system whose main difference from Git is that it uses a centralized server to keep track of the file changes. Git is distributed, meaning that everybody working on a Git project will have the complete repository locally on their computer. Here, we will show you the exact steps necessary to use Subversion instead of Git for this purpose:
/etc
repository:yum install subversion mkdir -p /var/local/svn/etc-repos svnadmin create --fs-type fsfs /var/local/svn/etc-repos
/etc
filesystem to our new repository:svn mkdir file:///var/local/svn/etc-repos/etc -m "Make a directory in the repository to correspond to /etc"
/etc
directory and add all the files to a new revision:cd /etc svn checkout file:///var/local/svn/etc-repos/etc ./ svn add *
svn commit -m "inital commit of the full /etc/ directory"
yum.conf
file:echo "FILE HAS CHANGED" >> yum.conf
svn commit -m "changing yum.conf files"
svn log -r 1:HEAD
/etc
import):svn diff -r 2:3
yum.conf
file:svn update -r 2 yum.conf