24/7/365 Support

Taking control in CentOS with GIT and Subversion

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 process, we will show you how to use modern version control systems such as GIT and Subversion to manage the versioning of config files.

To Start With: What Do You Need?

To complete this process, 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.

The Process:

Here in this process, 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:

  1. To begin, log in as root, install Git, and configure it by providing an email address and username (please substitute 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"
  2. Now, let’s create a new repository in the /etc directory:
    cd /etc/
    git init
  3. Now, after we have our new repository, let’s add all the files in the /etc/ directory under version control:
    git add *
  4. To commit the files to the repository creating your first revision, type the following:
    git commit -a -m "inital commit of the full /etc/ directory"
  5. Now, let’s change a file:
    echo "FILE HAS CHANGED" >> yum.conf
  6. Next, show the changes to your repository:
    git status
  7. Next, we will commit these changes and create a new revision of it:
    git commit -a -m "changing yum.conf files"
  8. Next, show all the commits so far:
    git log --pretty=oneline --abbrev-commit
  9. This will output the following commits on my system (the number hashes will be different on yours):
    8069c4a changing yum.conf
    5f0d50a inital commit of the full /etc directory
  10. Based on the output from the earlier step, we will now show all the differences between the two revision numbers (change the number hashes on your system based on the output from the earlier step):
    git diff 8069c4a 5f0d50a
  11. To complete this process, we will revert our changes to the original file revision (the initial commit):
    git checkout 5f0d50a

How Does It Work?

Here, in this process, 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 gitdiff- 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 process, 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.

There’s More:

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:

  1. First, install Subversion and configure a new server directory for our /etc repository:
    yum install subversion
    mkdir -p /var/local/svn/etc-repos
    svnadmin create --fs-type fsfs /var/local/svn/etc-repos
  2. Now, make an in-place import of the /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"
  3. Now, switch to the /etc directory and add all the files to a new revision:
    cd /etc
    svn checkout file:///var/local/svn/etc-repos/etc ./
    svn add *
  4. Now, create your first commit:
    svn commit -m "inital commit of the full /etc/ directory"
  5. Next, change the yum.conf file:
    echo "FILE HAS CHANGED" >> yum.conf
  6. Commit your changes to a new file revision:
    svn commit -m "changing yum.conf files"
  7. Now, show the change log:
    svn log -r 1:HEAD
  8. Show the file differences between our two commits (the first commit was the /etc import):
    svn diff -r 2:3
  9. Finally, revert to the first revision of our yum.conf file:
    svn update -r 2 yum.conf

 

 

 

Help Category:

What Our Clients Say