© Adam L. Davis 2020
A. L. DavisModern Programming Made Easyhttps://doi.org/10.1007/978-1-4842-5569-8_16

16. Version Control

Adam L. Davis1 
(1)
Oviedo, FL, USA
 

As soon as people start their programming careers, they are hit with the ton of bricks that is the version control system (VCS).

Version control software is used to keep track of, manage, and secure changes to files. This is a very important part of modern software development projects.

This book is going to cover two popular ones (but there are many more):
  • SVN (Subversion)

  • Git (git)

Every VCS has the following basic actions:
  • Add

  • Commit

  • Revert

  • Remove

  • Branch

  • Merge

IDEs have plug-ins for dealing with version control systems and usually have built-in support for popular systems such as SVN and Git.

Subversion

SVN1 was made as an improvement to an ancient and very popular VCS called CVS. It was a huge leap forward. Among other benefits, it allows any directory in the hierarchy to be checked out of the system and used. SVN requires a server to store the history, tags, and branches of the code. Programmers then use the SVN client to commit code changes.

To begin using SVN on the command line, you will check out a project and then commit files, for example:
1   svn checkout http://example.com/svn/trunk
2   svn add file
3   svn commit

Git

Git2 is a distributed version control system. This means that every copy of the source code contains the entire history of the code. However, unlike most other systems, it stores the history in a very compact and efficient and secure way—each commit is associated with a hash (a compact, but unique value generated from larger values by a one-way algorithm). It was initially created by the creator of Linux (Linus Torvalds) and is very popular.

To begin using Git on a new project, simply run the following command:
1   git init
Create a file called README and then commit it, as follows:
1   git add README
2   git commit -m "this is my comment"

../images/435475_2_En_16_Chapter/435475_2_En_16_Figa_HTML.jpg Install Git. Go to github.com3 and clone a repository, for example, git clone https://github.com/adamldavis/learning-groovy.git. Now create your own GitHub account, create a new repository, clone it, and follow the preceding instructions to add a new file to it. Lastly, use git push to push the changes to GitHub.

When you have a remote host set up in your local git repository (like when you cloned a repository from GitHub), you are able to push changes to it and pull changes from it. For example, the git push command pushes your commits to the remote host, and the git pull command gets changes from the host (that other developers might have put there).

Other helpful commands:
  • git log: Shows all commits, most recent first

  • git status: Shows the current status of your git repository

  • git show: Given a commit hash, shows all changes of that commit

  • git checkout: Given a branch name, loads that branch

  • git merge: Joins two or more development histories together

  • git branch: Can be used to list, create, or delete branches

  • git tag: Can be used to list, create, or delete tags

  • git help: Gives you helpful documentation. Gives help specific command when used like git help <command>

Mercurial

Mercurial4 predates Git but is very similar to it. It’s used for a lot of projects on Google Code and Bitbucket.5

../images/435475_2_En_16_Chapter/435475_2_En_16_Figb_HTML.jpg Install Mercurial. Go to Bitbucket and clone a repository using Mercurial, for example, hg clone https://bitbucket.org/adamldavis/dollar.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset