Svn Basic Tutorial 12040823s2813 Phpapp01

Embed Size (px)

Citation preview

SVN BASIC TUTORIAL

SVN BASIC TUTORIAL

Avoiding headaches

28.03.2012

Direct deploy

Developer 1StagingLiveDeveloper 2StagingLiveDesigner 1StagingLiveDesigner 2StagingLive28.03.2012

Removal of direct deploy

Developer 1StagingLiveDeveloper 2StagingLiveDesigner 1StagingLiveDesigner 2StagingLive

28.03.2012

Why not to directly deploy

Cant checkthe status of theenvironment

Race conditions (DEV1andDEV2work on a same file =>collisions)

Cant easily updatetheenvironment(full replace of the entire working copy needed)

28.03.2012

SVN

Subversion (SVN) is a SCM (Software Configuration Management) implementation

It allows totrack changesin files and directories

It allowsconcurrent developmenton the same files

It iscentralized(one server)

28.03.2012

SVN Interaction

SVN Server

Developer 1

Developer 2

Designer 1

Designer 2

Staging Server

Issue Tracker

Production Server28.03.2012

SVN development cycle

Get last project status from SVN server

Develop/Design

Test

Send work to SVN server

28.03.2012

SVN development (in SVN terms)

svn update

edit files

Test

svn commit

28.03.2012

How it works

Will make some examples withTortoiseSVNand thecommand lineto explain SVN

28.03.2012

Fetching an existing project

28.03.2012

Fetching an existing project

28.03.2012

Fetching an existing project

28.03.2012

Fetching an existing project

28.03.2012

Fetching an existing project

The .svn directoryisusedbysubversiontokeeptrackofchangesin thecurrentdirectorytree.Donotchangeit, copyitsomewhereelse or deleteit!

28.03.2012

Fetching an existing project

28.03.2012

Adding some files to the project

28.03.2012

Adding some files to the project

28.03.2012

Adding some files to the project

28.03.2012

Adding some files to the project

28.03.2012

Adding some files to the project

28.03.2012

Updating working copy

28.03.2012

Updating working copy

28.03.2012

Updating working copy

28.03.2012

Deploy with SVN

When having SSH access to a server, deploying and updating becomes as easy as:

$ ssh [email protected]

$ cd path/to/project

$ svn update

(Or "svn co" if the project is not yet deployed)

28.03.2012

Merging and conflicts

echohello to;

echo $username;

Developer 1echo hello world ;

echo$_GET[username];

Developer 2In the following schema, two developers try to commit changes to a same file:

RED= changed by developer

28.03.2012

How merging works

When Developer 2 tries to commit, SVN will tell him that his copy is outdated, he will have to update it

28.03.2012

How merging works

How merging works

Merging wont cause any changes on the server, you will first get all the changeslocally, so that you canreviewthem. Heres the result of this merge case:

We can then

$ svn commit -m "Merged changes of marcos commit"

28.03.2012

Merging workflow

svn commit

Cant commit (outdated working copy)

svn update

svn tries to merge

Developer verifies merge

28.03.2012

What if SVN cant merge?

svn commit

Cant commit (outdated working copy)

svn update

svn tries to merge

SVN couldnt merge????????

28.03.2012

SVN Conflicts

echohello everybody;

echo $_GET[username];

Developer 1echogoodbye everybody;

echo $_GET[username];

Developer 2SVNconflictshappen when two developers act on asame file in the same line:

RED= changed by developer

28.03.2012

SVN Conflicts

28.03.2012

SVN Conflicts

index.phpisamergedviewof theconflict:

index.php.r8istheversionbeforethe update

index.php.r9istheversionasin SVN server

index.php.mineistheversionyouhadinyourdirectorybeforecommitting

28.03.2012

SVN Conflicts

We can edit the files until all conflicts are solved, then tell SVN it should accept our new working copy:

28.03.2012

SVN Conflicts

svn commit

Cant commit (outdated working copy)

svn update

svn tries to merge

SVN couldnt merge

Manually edit conflicts

Mark conflicts as resolved

28.03.2012

Parallel development

28.03.2012

SVN branching

Main projectThe main project and its featuresNext major version updateKeeps track of changes to be merged into the next major release of the softwareBugfix for a known bugWork in progress to fix a known bugNew feature that has to be addedA new feature that requires some work without being influenced by other bugfixes and changesAlternate version to show to the customerA slightly different version of the site that the customer has requested, but that isnt ready yet, and could be discarded28.03.2012

Thisisactuallyhowgit-flow by nvie.comhandlesdevelopment,butSVNcouldalsouseit!

What is a branch?

In SVN terms,a branch is just a copyof a current tree. Lets create a branch to develop an alternate layout for the site:

svn copy -m creating green site dev branch
svn://path/to/repo/trunk
svn://path/to/repo/branches/wide-layout

(in TortoiseSVN it is under branch/tag in context menu)

28.03.2012

Switching working copy

Given that you checked out:

svn://project/path/trunk

You can nowswitchto a branch by doing

svn switch svn://project/path/branches/red

and you will be working on that copy

28.03.2012

Merging branches

Once completed developing on a branch, you may want tomerge changes back:

28.03.2012

Merging branches

Like normal conflict merging!

28.03.2012

First you switch to the branch you want changes to be merged to:


$svnswitch svn://path/to/target/branch

Thenyou merge a set of revision from the branch you developed on (here 25 to latest):

$svnmerge -r25:HEAD svn://path/to/merged/branch

Then SVN will merge any conflicts or set conflicted state and allow you to check what happened. After fixing conflicts:


$svnci -m merging changes from new-layout branch

Tags

Tags aremarkersused for deployment, mainly for major release versions:

28.03.2012

Tags

Tags are copies, exactly like branches:

$ svn copy
-m tagging version 1.1 of the project
svn://path/to/project
svn://path/to/tags/1.1

Except that youNEVERcommit on tags!

28.03.2012

svn:externals

Externals are links to other repositories:


$svnpropsetsvn:externals
css/commonsvn://company/common/css/files
./

Externals are not part of the repository, they are just fetched with the repository (useful for deploying applications!)

28.03.2012

Best practices

28.03.2012

Update your projects before working

28.03.2012




Do not commit broken code/functionality!

(Test before committing if possible!)

28.03.2012



Commit as soon as a piece of the functionality iscompleted

28.03.2012

Branch life should not be too long

Long living branches increase merge conflicts!

This forces you to keep small units of work

28.03.2012

Every commit should have a purpose. Commits with no purpose to be avoided!

If possible, avoid multiple commits on separate files being part of one functionality

28.03.2012



Never commit generated code/data!



Generated code can produce dozens of useless commits, conflicts and generally, headaches!

28.03.2012

EVERY

COMMIT

MUST

HAVE

DESCRIPTION

28.03.2012

Examples ofBADcommit messages:

Fixed bug

Updated

Saved work

Updating

Merging changes

Saving work of 10/3/2010

28.03.2012

Examples ofGOODcommit messages:

Adding CSS definitions needed to create alightboxoverlay when focus is onthe offersiframe

Fixed bug with session expiring after browser restart on IE7

Updated the logo with the new colors provided

Adding interfaces for the new blog feature

The interfaces are still quite lightweight, but should be refreshed in the next days

(yes, multiline commits are allowed!)

28.03.2012

If using an issue tracker (Jira, Trac, Bugzilla, Redmine, etc.), write the issue ID in the commit message:

Fixed iframe width causing scrollbars to appear when not needed as ofPRJ-123

Optimal process

28.03.2012

Resolve conflicts immediatelyCommit (with appropriate message)Test changesDevelopIf theres errors, fix them first! (do not work on broken projects)Build (test first)Update working copy28.03.2012

Suggested Workflow

Thisisactuallyhowgit-flow by nvie.comhandlesdevelopment,butSVNcouldalsouseit!

Titelmasterformat durch Klicken bearbeiten

Textmasterformat bearbeiten

Zweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

28.03.2012

28.03.2012

Textmasterformat bearbeitenZweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

Titelmasterformat durch Klicken bearbeiten

Formatvorlage des Untertitelmasters durch Klicken bearbeiten

28.03.2012

28.03.2012

Textmasterformat bearbeitenZweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

Titelmasterformat durch Klicken bearbeiten

Textmasterformat bearbeiten
Zweite Ebene
Dritte Ebene
Vierte Ebene
Fnfte Ebene

28.03.2012

28.03.2012

Textmasterformat bearbeitenZweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

Titelmasterformat durch Klicken bearbeiten

Textmasterformat bearbeiten

28.03.2012

28.03.2012

Textmasterformat bearbeitenZweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

Titelmasterformat durch Klicken bearbeiten

Textmasterformat bearbeiten
Zweite Ebene
Dritte Ebene
Vierte Ebene
Fnfte Ebene

Textmasterformat bearbeiten
Zweite Ebene
Dritte Ebene
Vierte Ebene
Fnfte Ebene

28.03.2012

28.03.2012

Textmasterformat bearbeitenZweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

Titelmasterformat durch Klicken bearbeiten

Textmasterformat bearbeiten

Textmasterformat bearbeiten
Zweite Ebene
Dritte Ebene
Vierte Ebene
Fnfte Ebene

Textmasterformat bearbeiten

Textmasterformat bearbeiten
Zweite Ebene
Dritte Ebene
Vierte Ebene
Fnfte Ebene

28.03.2012

28.03.2012

Textmasterformat bearbeitenZweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

Titelmasterformat durch Klicken bearbeiten

28.03.2012

28.03.2012

Textmasterformat bearbeitenZweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

28.03.2012

28.03.2012

Textmasterformat bearbeitenZweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

Titelmasterformat durch Klicken bearbeiten

Textmasterformat bearbeiten
Zweite Ebene
Dritte Ebene
Vierte Ebene
Fnfte Ebene

Textmasterformat bearbeiten

28.03.2012

28.03.2012

Textmasterformat bearbeitenZweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

Titelmasterformat durch Klicken bearbeiten

Textmasterformat bearbeiten

28.03.2012

28.03.2012

Textmasterformat bearbeitenZweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

Titelmasterformat durch Klicken bearbeiten

Textmasterformat bearbeiten

Zweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

28.03.2012

28.03.2012

Textmasterformat bearbeitenZweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

Titelmasterformat durch Klicken bearbeiten

Textmasterformat bearbeiten

Zweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene

28.03.2012

28.03.2012

Textmasterformat bearbeitenZweite Ebene

Dritte Ebene

Vierte Ebene

Fnfte Ebene