Вы находитесь на странице: 1из 52

Version Control Systems

Yury Yineth Nio Roa


yyninor@unal.edu.co
Software Engineering 2
UNIVERSIDAD NACIONAL DE COLOMBIA

Content
Version Control Systems
Git Basics
Installing Git
Getting a Git repository
Recording changes to the repository
Viewing the commit history
Branching and Merging
Software Engineering 2

What is Version Control System


[VCS]?

Software Engineering 2

Background [VCS]
[VCS] is a system that records the changes of a file
or set of files over time.
A [VCS] allows:

Revert files back to a previous state.


Revert the entire project back to a previous state.
Review changes made over time.
See who last modified something.

There are 3 types of [VCSs].


Software Engineering 2

What are the types of [VCSs]?

Software Engineering 2

Types of [VCSs]
Before [VCSs]
The method of many people to control versions was
to copy files into a directory by each version.

Where is the
last version?

Software Engineering 2

Types of [VCSs]
Local [VCSs]
These systems had a simple database that kept all the
changes to files under revision control.

[BOOK] ProGit
Software Engineering 2

Types of [VCSs]
Centralized [VCSs]
These systems have a single server that contains all
the versioned files and a number of clients that check
out files from that central place.

[BOOK] ProGit
Software Engineering 2

Types of [VCSs]
Distributed [VCSs]
In these systems the clients dont just check out the
latest snapshot of the files, they fully mirror the
repository.

[BOOK] ProGit
Software Engineering 2

I dont understand several terms

Software Engineering 2

Terminology
Term

Description

Contains the history, versions over time, branches and


Repository tags.
Each copy of the repository is a complete repository.
Working
tree
Branch
Tag

Contains the content of a commit which you can


checkout.
Is a separate code line with its own history.
One of the branches is the default (master).
Points to a commit which uniquely identifies a version
of the repository.
[URL] http://www.vogella.com/articles/Git/article.html

Software Engineering 2

Terminology
Term

Description

Commit

An user commit his changes into a repository.


A new commit uniquely identifies a new revision of
the repository.

URL

An URL determines the location of the repository.

Revision

HEAD

Represents a version of the source code.

Is a pointer to the currently selected commit object


[URL] http://www.vogella.com/articles/Git/article.html

Software Engineering 2

How does Git work?

Software Engineering 2

Git
Other
systems

[BOOK] ProGit

Git
[BOOK] ProGit
Software Engineering 2

Git Features
Nearly every operation is local.
Git has Integrity.
Git generally only
adds data.
The 3 states:
Modified
Staged
C0mmitted
[BOOK] ProGit
Software Engineering 2

Git Features
A Git workflow like this:
A user modifies files in the working directory.
A user stages the files.
A user does a commit.
If it was changed since it was checked out but has not
been staged Modified.
If a file is modified but has been added to the staging
area Staged.
If a version of a file is in the Git directory Committed.
Software Engineering 2

Installing Git
http://git-scm.com/book/en/Getting-StartedInstalling-Git#Installing-from-Source
On Linux
$ apt-get install git

On Windows
Download the installer .exe file from the GitHub page and
run it:
http://msysgit.github.com/
Software Engineering 2

First-Time Git Setup


Checking your settings
$ git config list

Setting your identity


$ git config --global user.name Yury
$ git config --global user.email yyninor@unal.edu.co

Choose diff tool


$ git config --global merge.tool vimdiff
You can choose kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff,
ecmerge, and opendiff as ddiff tool.

Software Engineering 2

Getting a Git Repository


There are 2 approaches:
Take an existing directory and import it into Git.
Clone an existing Git repository from another server.

Initializing a repository in an existing directory


$ git init
$ git add .
$ git commit -m initial project version

Cloning an existing repository


$ git clone git://github.com/davidmr/scio.git

Software Engineering 2

How to register changes?

Software Engineering 2

Register Changes
Background file status

[BOOK] ProGit
Software Engineering 2

Class Exercise
1. When you first clone a repository, what is the
state of all files?
2. When you add a file to working
copy, what is the state of this file?
3. When you edit a tracked file, what is the state of
this file?

Software Engineering 2

Register Changes
Checking the status of files

$ git status
# On branch master nothing to commit
(working directory clean)

If README is added
$
#
#
#
#
#

git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will
be committed)
README nothing added to commit but
files present (use "git add" to track)

untracked

Software Engineering 2

Register Changes
Tracking new files
$ git add README

If run status again


$
#
#
#
#
#
#

git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: README

Software Engineering 2

Register Changes
Viewing staged and unstaged changes

[BOOK] ProGit
Software Engineering 2

Register Changes
Committing changes
$ git commit m a message
$ git commit -m "Story 182: Fix
[master]: created 463dc4f: Fix
2 files changed, 3 insertions(+),
create mode 100644 README

0 deletions(-)

You can see in the output commit:


Which branch you committed to (master).
What SHA-1 checksum the commit has (463dc4f).
How many files were changed.
Software Engineering 2

Register Changes
Removing files
$ git rm [file]

The file is only removed from the working directory:


$
$
#
#
#

git rm README.txt
git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what
will be committed)
# deleted: README.txt

Software Engineering 2

How to view the commit


history?

Software Engineering 2

Viewing the Commit History


The most basic and powerful tool to do this is:
$ git log

[BOOK] ProGit
Software Engineering 2

Viewing the Commit History


Using Gitk or Git GUI

Software Engineering 2

I want to be able to collaborate


on any Git project? Is it possible?

Software Engineering 2

Working with Remotes


Remote repositories are versions of the project that
are hosted on the Internet or network somewhere.
Collaborating with others involves managing these
remote repositories, pushing and pulling data to and
from them.
Showing remotes
git remote

Adding remotes
git remote add [shortname] [url]
Software Engineering 2

Working with Remotes


Fetching to remotes
$ git fetch [remote-name]
fetch command doesnt automatically merge local work with the
remote. Its necessary to merge manually.
$ git pull [remote-name]

Pushing to remotes
$ git push [remote-name] [branch-name]

Software Engineering 2

Is possible tagging releases in


Git?
Because in SVN is possible

Software Engineering 2

Tagging
Git has the ability to tag specific points in history as
being important.
Listing tags
$ git tag
v0.1
v1.3

Lightweight tags
$ git tag v1.4-lw

Creating Tags
Lightweight
Annotated

Annotated tags
$ git tag -a v1.4
-m 'my version 1.4

Software Engineering 2

Before we finish, Can we review


branching?

Software Engineering 2

Git Branching
Branching is a mechanism to diverge from the main
line of development and continue to do work.
When a user commit, Git stores a object with:
A pointer to the snapshot of the content staged.
The author and message metadata.
Zero or more pointers to the commit or commits that
were the direct parents of this commit.

Software Engineering 2

Git Branching
Lets assume that we have a directory containing
three files, and we stage them all and commit.

[BOOK] ProGit
Software Engineering 2

Git Branching
After two more commits the history might look
something like as:

[BOOK] ProGit

Software Engineering 2

What happens if we create a


new branch?

Software Engineering 2

Git Branching

$ git branch testing

$ git checkout testing

[BOOK] ProGit

A shorthand
$ git checkout -b testing

Software Engineering 2

Git Branching
$ vim test.rb
$ git commit -a -m 'made a change'

$ git checkout master

[BOOK] ProGit

Software Engineering 2

Class Exercise
1. What happen if we make a few changes and
commit again?

[BOOK] ProGit

Software Engineering 2

Solution Exercise

[BOOK] ProGit

Software Engineering 2

Class Exercise
1. Define the
workflow:
1.
2.
3.
4.
5.
6.

commands

necessary

to

next

Clone a project that is hosting in


git://github.com/yyninor/myweb.git
Do work on a web site.
Publish these changes in the remote.
Create a branch for a new story youll working on.
Do some work in that branch.
Publish these changes in your local repository.

Software Engineering 2

Solution

[BOOK] ProGit
Software Engineering 2

Creating new branch hotfix


Suppose that we have to create a new branch
hotfix from master.

[BOOK] ProGit

Software Engineering 2

Merging
Suppose that after hotfix is tested, we want to
merge hotfix to master.

[BOOK] ProGit
Software Engineering 2

Merging
Remember iss53 branch. Suppose weve decided
that our iss53 work is complete and ready to be
merged into the master branch.
What is the difference?

Vs

Software Engineering 2

Merging

Software Engineering 2

Hosting SD Services
GitHub is a web based hosting
service for software development
projects that use the Git revision
control system.
Google Code is Google's site for
developer tools, APIs and technical
resources.
SourceForge is a web-based source
code repository.
Software Engineering 2

Assignment 5
Choose a VCS to develop your project and publish
how to clone the repository in the versioning
section of your project page.
Read Section 5.1 of the ProGit Book, because next
we will make a quiz about this topic.
Decide what workflow are you going
to use within your project. Justify
your answer in the versioning section.
Software Engineering 2

Вам также может понравиться