version control

50
VERSION CONTROL SYSTEMS Saman Najafi

Upload: saman-najafi

Post on 09-Aug-2015

42 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Version control

VERSION CONTROL SYSTEMSSaman Najafi

Page 2: Version control

WHAT IS VCS?

A TOOLto track changes of source code

What had changedWhen changedWhy changedWho changed it

Page 3: Version control

WHY USING VCS?

Some expert’s comments:

Page 4: Version control

WHY USING VCS?

Some expert’s comments (cont.):

Page 5: Version control

WHY USING VCS?

Some expert’s comments (cont.):

“If it’s not in source control, it doesn’t exist.”

Page 6: Version control

WHY USING VCS?

And really why? Prevent from accidentally

deletion Access to the different and older

versions of your files Some logs maybe useful while

reviewing your project Managing conflicts in team

works

Ayyyy…

Page 7: Version control

WHY USING VCS?

And really why? (cont.)

Create Several versions with different functionalities and features

Share your code, or let other people work on your code

Experiment with a new feature without interfering with working code

Page 8: Version control

SCENARIO I: BUG FIX

Time

1.0

First public release of the hot new product

Rele

ase

s

Page 9: Version control

SCENARIO I: BUG FIX

1.0

Rele

ase

s

Internal development continues, progressing to version 1.31.3

Time

Page 10: Version control

SCENARIO I: BUG FIX

1.0

Time

Rele

ase

s

A fatal bug is discovered in the product (1.0), but 1.3 is not stable enough to release. Solution: Create a version based on 1.0 with the bug fix.

1.3

1.0 bugfix

Page 11: Version control

SCENARIO I: BUG FIX

1.0

Time

Rele

ase

s

The bug fix should also be applied to the main code line so that the next product release has the fix.1.3

1.0 bugfix

1.4

Page 12: Version control

SCENARIO I: BUG FIX

1.0

Time

Rele

ase

s

Note that two separate lines of development come back together in 1.4.

This is merging or updating.

1.3

1.0 bugfix

1.4

Page 13: Version control

SCENARIO II: NORMAL DEVELOPMENT

1.5

Time

Rele

ase

s

You are in the middle of a project with three developers named a, b, and c.

Page 14: Version control

SCENARIO II: NORMAL DEVELOPMENT

1.5

Time

Rele

ase

s

The local versions isolate the developers from each other’s possibly unstable changes. Each builds on 1.5, the most recent stable version.

1.5a

1.5b

1.5c

Page 15: Version control

SCENARIO II: NORMAL DEVELOPMENT

1.5

Time

Rele

ase

s

1.5a

1.5b

1.5c

1.6

At 4:00 pm everyone checks in their tested modifications. A check in is a kind of merge where local versions are copied back into the version control system.

Page 16: Version control

SCENARIO II: NORMAL DEVELOPMENT

1.5

Time

Rele

ase

s

1.5a

1.5b

1.5c

1.6

In many organizations check in automatically runs a test suite against the result of the check in. If the tests fail the changes are not accepted.

This prevents a sloppy developer from causing all work to stop by, e.g., creating a version of the system that does not compile.

Page 17: Version control

SCENARIO III: DEBUGGING

1.5

Time

Rele

ase

s

1.6

You develop a software system through several revisions.

1.7

Page 18: Version control

SCENARIO III: DEBUGGING

1.5

Time

Rele

ase

s

1.6

In 1.7 you suddenly discover a bug has crept into the system. When was it introduced?

With version control you can check out old versions of the system and see which revision introduced the bug.

1.7

Page 19: Version control

SCENARIO IV: LIBRARIES

Time

Rele

ase

s

You are building software on top of a third-party library, for which you have source.

Library A

Page 20: Version control

SCENARIO IV: LIBRARIES

Time

Rele

ase

s

Library A

You begin implementation of your software, including modifications to the library.

0.7

Page 21: Version control

SCENARIO IV: LIBRARIES

Time

Rele

ase

s

Library A 0.7

Library B

A new version of the library is released. Logically this is a branch: library development has proceeded independently of your own development.

Page 22: Version control

TWO MAIN TYPES OF VCS

Centralized version control

Page 23: Version control

CENTRALIZED VERSION CONTROL

Have a single server that contains all the versioned files, and a number of clients that check out files from that central place.

For many years, this has been the standard for version control

Page 24: Version control

Distributed version control

Page 25: Version control

DISTRIBUTED VERSION CONTROL SYSTEMS

This is where Distributed Version Control Systems (DVCSs) step in.

In a DVCS (such as Git, Mercurial, Bazaar or Darcs), clients don’t just check out the latest snapshot of the files: they fully mirror the repository.

Thus if any server dies, and these systems were collaborating via it, any of the client repositories can be copied back up to the server to restore it. Every checkout is really a full backup of all the data

This allows you to set up several types of workflows that aren’t possible in centralized systems, such as hierarchical models.

Page 26: Version control

KEY TERMS

Projects : set of files in version control Version control doesn’t care what files

Not a build system Or a test system

Though there are often hooks to these other systems

Page 27: Version control

KEY TERMS

Repository : kind of DB stores changes on source code during its life (such as .git directory in the git system or .svn in the sub version)

Page 28: Version control

KEY TERMS

Working directory : local directory of files, where you make changes

Page 29: Version control

KEY TERMS

Revision: snapshot of code at specific timeConsider

Check out a file Edit it Check the file back in

This creates a new version of the file Usually increment minor version number E.g., 1.5 -> 1.6

Page 30: Version control

KEY TERMS

Revision (Cont.) For efficiency, don’t store entire new file

Store diff with previous version Minimizes space Makes check-in, check-out potentially slower

Must apply diffs from all previous versions to compute current file

Page 31: Version control

KEY TERMS

With each revision, system stores The diffs for that version The new minor version number Other metadata

Author Time of check in Log file message

Head: The latest revision in current branch

Page 32: Version control

KEY TERMS

Branch: a branch is just two revisions of a file Two people check out 1.5 Check in 1.5.1 Check in 1.5.2

Notes Normally checking in does not create a branch

Changes merged into main code line Must explicitly ask to create a branch

Page 33: Version control

KEY TERMS

Merging: Start with a file, say 1.5

Bob makes changes A to 1.5

Alice makes changes B to 1.5

Assume Alice checks in first Current revision is 1.6 = apply(B,1.5)

Page 34: Version control

KEY TERMS

Merging (Cont.)

Now Bob checks in System notices that Bob checked out 1.5 But current version is 1.6 Bob has not made his changes in the current

version!

The system complains Bob is told to update his local copy of the code

Page 35: Version control

KEY TERMS

Merging (Cont.)

Bob does an update This applies Alice’s changes B to Bob’s code

Remember Bob’s code is apply(A,1.5)

Two possible outcomes of an update Success Conflicts

Page 36: Version control

KEY TERMS

Merging (Cont.)

Assume thatapply(A,apply(B,1.5) = apply(B,apply(A,1.5))

Then order of changes didn’t matter Same result whether Bob or Alice checks in first The version control system is happy with this

Bob can now check in his changes Because apply(B,apply(A,1.6)) = apply(B,1.6)

Page 37: Version control

KEY TERMS

Merging (Cont.)

Assume apply(A,apply(B,1.5) ¹ apply(B,apply(A,1.6))

There is a conflict The order of the changes matters Version control will complain

Page 38: Version control

KEY TERMS

Conflicts: Arise when two programmers edit the same

piece of code One change overwrites another

1.5: a = b;Alice: a = b++;Bob: a = ++b;

The system doesn’t know what should be done, and so complains of a conflict.

Page 39: Version control

KEY TERMS

Conflicts (Cont.):

System cannot apply changes when there are conflicts Final result is not unique Depends on order in which changes are applied

Version control shows conflicts on update Generally based on diff3

Conflicts must be resolved by hand

Page 40: Version control

KEY TERMS

Conflicts (Cont.):

Conflict detection is based on “nearness” of changes Changes to the same line will conflict Changes to different lines will likely not conflict

Note: Lack of conflicts does not mean Alice’s and Bob’s changes work together

Page 41: Version control

KEY TERMS

Example With No Conflict: Revision 1.5: int f(int a, int b) { … }

Alice: int f(int a, int b, int c) { … } add argument to all calls to f

Bob: add call f(x,y)

Merged program Has no conflicts But will not even compile

Page 42: Version control

KEY TERMS

Locking: Keep file in lock to prevent other users

changes 1. Strict locking2. Optimistic locking

Page 43: Version control

KEY TERMS

Pushing: Transfer changes of local repository to

remote repository

Page 44: Version control

KEY TERMS

Pulling: Get last update from remote repository

to workspace

Page 45: Version control

GETTING STARTED- GIT

The major difference between Git and any other VCS (Subversion and friends included) is the way Git thinks about its data..

Conceptually, most other systems store information as a list of file-based changes. These systems (CVS, Subversion, Perforce, Bazaar, and so on) think of the information they keep as a set of files and the changes made to each file over time

Page 46: Version control

CHECKINS OVER TIME

Page 47: Version control

CHECKINS OVER TIME

Git thinks of its data more like a set of snapshots of a mini filesystem.

Every time you commit, or save the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot.

To be efficient, if files have not changed, Git doesn’t store the file again—just a link to the previous identical file it has already stored

Page 48: Version control

GIT STORES DATA AS SNAPSHOTS OF THE PROJECT OVER TIME.

Page 49: Version control

GIT STRUCTURE

Page 50: Version control