Professional Documents
Culture Documents
Practices
Chapter 6
Revision Control
friesbaht 1
Chapter Outline
Introduction to revision Control
Version Control Configuration and Use
Cloning an existing repository
friesbaht
Introduction
friesbaht
Cont.…
It permits many people to work on the same parts of a
project without worrying that their changes will
overwrite the work of anyone else.
The collection of revisions and their metadata is
called a repository or repo.
The repository represents a step-by-step
chronological record of every change made to help
project managers revert all or part of the project to a
previous state if necessary.
friesbaht
How revisions are made?
Revision control systems are usually hosted on
a networked server.
After the repository is set up, it involves the
following steps:
friesbaht
Cont.….
S-2:- If the developer wants to edit a file that is
already part of the project, the file must be checked
out (is known as the "head").
friesbaht
Cont…
S-4:- If someone else has checked in revisions to the same
file since the last time the developer checked it out, the
system announces that there are conflicts.
It calculates the differences line-by-line, and the
developers who made the changes must agree upon how
their individual changes should be merged.
friesbaht
The stages of developing a software application:
Requirements Analysis
High-level Design
Low-level Design
Implementation
Integration
Deploy (SDL)
Maintain (SDL)
friesbaht
In many cases, multiple projects
run concurrently
friesbaht
SE 4091
Dileep Kumar G.
On a single project, a team of software
engineers work together toward a release
An engineer may be
responsible for an entire class
Harry and Sally get their own respective local Working Copies of the
Master File in the Repository
USB/SD drive
Cloud drive
Google drive
Dropbox
iCloud
‘’
‘’
friesbaht
Revision/Version History might help
…but USB/SD, private network drives do not
maintain revision history
friesbaht
Special-purpose Revision Control
Systems have been around a lot
longer than Google Drive or Dropbox
SCCS, 1972 (IBM)
RCS, 1982 (Unix)
SourceSafe 1995 (Microsoft)
CVS, 1986 (multi-platform)
SVN, 2000 (multi-platform)
Git and Mercurial, 2005 (multi-platform)
friesbaht
The Lock-Modify-Unlock solution
friesbaht
Subversion is an open-source version
control system that is available and still
supported for many platforms
Windows
Mac
Linux
friesbaht
Subversion’s main drawback is the
centralized nature of the Repository
friesbaht
Repositories can also manage and track differences
between parallel revisions of a document
friesbaht
Git uses checksums
Git generates a unique SHA-1 hash – 40
character string of hex digits, for every
commit.
Often we only see the first 7 characters:
1677b2d Edited first line of readme
258efa7 Added line to readme
0e52da7 Initial commit
friesbaht
A Local Git project has three areas
friesbaht
Basic Workflow
Basic Git workflow:
1. Modify files in your working directory.
You can call git config --list to verify these are set.
These will be set globally for all Git projects you work
with.
You can also set variables on a project-only basis by not
using the
--global flag.
You can also set the editor that is used for writing commit
messages:
$ git config --global core.editor emacs (it is vim by
friesbaht
default)
Create a local copy of a repo
2. Two common scenarios: (only do one of these)
a) To clone an already existing repo to your current directory:
$ git clone <url> [local-dir-name]
This will create a directory named local-dir-name, containing a
working copy of the files from the repo, and a .git directory
(used to hold the staging area and your actual repo)
b) To create a Git repo in your current directory:
$ git init
This will create a .git directory in your current directory.
Then you can commit files in that directory into the repo:
$ git add file1.java
$ git commit –m “initial project version”
friesbaht
Git commands
command description
git clone url [dir] copy a git repository so you can add to it
git add files adds file contents to the staging area
git commit records a snapshot of the staging area
git status view the status of your files in the working
directory and staging area
git diff shows diff of what is staged and what is
modified but unstaged
git help [command] get help info about a particular command
git pull fetch from a remote repo and try to merge
into the current branch
git push push your new branches and data to a
remote repository
others: init, reset, branch, checkout, merge, log, tag
friesbaht
Init a repository
zachary@zachary-desktop:~/code/gitdemo$ git init
Initialized empty Git repository in /home/zachary/code/gitdemo/.git/
zachary@zachary-desktop:~/code/gitdemo$ ls -l .git/
total 32
drwxr-xr-x 2 zachary zachary 4096 2011-08-28 14:51 branches
-rw-r--r-- 1 zachary zachary 92 2011-08-28 14:51 config
-rw-r--r-- 1 zachary zachary 73 2011-08-28 14:51 description
-rw-r--r-- 1 zachary zachary 23 2011-08-28 14:51 HEAD
drwxr-xr-x 2 zachary zachary 4096 2011-08-28 14:51 hooks
drwxr-xr-x 2 zachary zachary 4096 2011-08-28 14:51 info
drwxr-xr-x 4 zachary zachary 4096 2011-08-28 14:51 objects
drwxr-xr-x 4 zachary zachary 4096 2011-08-28 14:51 refs
friesbaht
Stage the Changes
zachary@zachary-desktop:~/code/gitdemo$ git 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: hello.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
friesbaht
Review Changes
zachary@zachary-desktop:~/code/gitdemo$ git add hello.txt
zachary@zachary-desktop:~/code/gitdemo$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: hello.txt
#
friesbaht
Committing files
The first time we ask a file to be tracked, and every time
before we commit a file we must add it to the staging area:
$ git add README.txt hello.java
This takes a snapshot of these files at this point in time and adds
it to the staging area.
To move staged changes into the repo we commit:
$ git commit –m “Fixing bug #22”
friesbaht
Viewing logs
To see a log of all changes in your local repo:
$ git log or
friesbaht
Pulling and Pushing
Good practice:
1. Add and Commit your changes to your local repo
2. Pull from remote repo to get most recent changes (fix conflicts if
necessary, add and commit them to your local repo)
3. Push your changes to the remote repo
To fetch the most recent updates from the remote repo into your local repo,
and put them into your working directory:
$ git pull origin master
To push your changes from your local repo to the remote repo:
$ git push origin master
Notes: origin = an alias for the URL you cloned from
master = the remote branch you are pulling from/pushing to,
(the local branch you are pulling to/pushing from is your current branch)
Note: On attu you will get a Gtk-warning, you can ignore this.
friesbaht
Branching
To create a branch called experimental:
$ git branch experimental
To list all branches: (* shows which one you are currently on)
$ git branch
To switch to the experimental branch:
$ git checkout experimental
Later on, changes between the two branches differ, to
merge changes from experimental into the master:
$ git checkout master
$ git merge experimental
friesbaht
Self-Review Questions
1.List out tools that exist for version control?
2.What are the features of distributed version
control?
3.List out Git commands?
4.Write code snippet for creating a jar file?
5.Write code snippet to demonstrate the concept
of unit testing using JUnit?
friesbaht