You are on page 1of 13

1-3- Version Control 2/23/21

1 2

Outline
1. Introduction
OBJECT-ORIENTED PROGRAMMING 2. Models
1.3 VERSION CONTROL 3. Vocabulary
Nguyen Thi Thu Trang 4. Tools
trangntt@soict.hust.edu.vn

1 2

3 4

Why version control? (1/2) Why version control? (2/2)


• Scenario 1: • Your program worked well enough yesterday
• Your program is working • You made a lot of improvements last night...
• You change “just one thing” • ...but you haven't gotten them to work yet
• Your program breaks
• You need to turn in your program now
• You change it back
• Your program is still broken--why?
• Has this ever happened to you?
• Has this ever happened to you?

3 4

NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 1


1-3- Version Control 2/23/21

5 6

Version control for teams (1/2) Version control for teams (2/2)
• Scenario: • Scenario:
• You change one part of a program--it works • You make a number of improvements to a class
• Your co-worker makes a number of different
• Your co-worker changes another part--it works
improvements to the same class
• You put them together--it doesn’t work
• How can you merge these changes?
• Some change in one part must have broken
something in the other part
• What were all the changes?

5 6

7 8

Tools: diff Tools: jDiff


• There are a number of tools that help you spot • jDiff is a plugin for the jEdit editor
changes (differences) between two files • Advantages:
• Tools include diff, rcsdiff, jDiff, etc. • Everything is color coded
• Of course, they won't help unless you kept a copy • Uses synchronized scrolling
of the older version • It's inside an editor--you can make changes directly

• Differencing tools are useful for finding a small • Disadvantages:


number of differences in a few files • Not stand-alone, but must be used within jDiff
• Just a diff tool, not a complete solution

7 8

NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 2


1-3- Version Control 2/23/21

9 10

Tools: jDiff Version control systems


• A version
control system (often called a source
code control system) does these things:
• Keeps multiple (older and newer) versions of everything
(not just source code)
• Requests comments regarding every change
• Allows “check in” and “check out” of files so you know
which files someone else is working on
• Displays differences between versions

9 10

11 12

Outline 2. Versioning Models


1. Introduction • Lock-Modify-Unlock
2. Versioning Models vs. Copy-Modify-Merge
3. Vocabulary • Central Version Control
4. Tools vs. Distributed Version Control

11 12

NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 3


1-3- Version Control 2/23/21

13 14

2.1. The Lock-Modify-Unlock


The Lock-Modify-Unlock Model (1) Model 2.1. The Lock-Modify-Unlock Model (2)
The Lock-Modify-Unlock Model (2)
Andy and Bobby
check-out file A.
Repository Andy locks file A and Repository
The check-out is done
begins modifying it.
without locking. They A A
just get a local copy. Check-out

Check-out Lock
A A

A Аndy

Bobby (Local Edit)


Bobby
Andy Andy
32 33

13 14

15 16

2.1. The Lock-Modify-Unlock Model (3) 2.1. The Lock-Modify-Unlock


The Lock-Modify-Unlock Model (4) Model (4)
The Lock-Modify-Unlock Model (3)

Bobby tries to lock the


file too, but she can’t. Andy commits his changes Repository
Repository
and unlocks the file. Andy
Bobby waits for Andy to
A
finish and unlock the file. Wait

Commit
A
A

Andy
Andy

Bobby
Bobby
Andy
Andy
35
34

15 16

NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 4


1-3- Version Control 2/23/21

17 18

The Lock-Modify-Unlock Model (6)


2.1. The Lock-Modify-Unlock
The Lock-Modify-Unlock Model (5) Model (5) 2.1. The Lock-Modify-Unlock Model (6)

Now Bobby can take the Bobby finishes,


Repository
modified file and lock it. Repository commits her changes
and unlocks the file. Andy
Bobby edits her local Andy Bobby
copy of the file. Commit
Lock

Andy Andy
Bobby

Andy Andy
(Local Edit)

Bobby
Andy Bobby
36 Andy
37

17 18

19 20

The Lock-Modify-Unlock Model (7)


2.1. The Lock-Modify-Unlock Model (7) The Copy-Modify-Merge Model (1) Model
2.2. The Copy-Modify-Merge
Andy and Bobby
Andy updates the check-out a file A.
Repository
changes from the Repository
Andy The check-out is
repository.
Bobby done without A
locking. Check-out

Update Andy Check-out


Bobby A

Andy
Bobby A

Bobby
Bobby
Andy
38
Andy
40

19 20

NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 5


1-3- Version Control 2/23/21

21 22

The Copy-Modify-Merge Model (2) Model (2) The Copy-Modify-Merge Model (3)
2.2. The Copy-Modify-Merge 2.2. The Copy-Modify-Merge Model (3)
Both of them
edit the local Bobby commits Repository
Repository
copies of the her changes to
file (in the A
the repository. Bobby Commit
same time).

Bobby Bobby

Andy Andy
(Local Edit)

(Local Edit) Bobby


Bobby
Andy Andy
42
41

21 22

23 24

The Copy-Modify-Merge Model (4)


2.2. The Copy-Modify-Merge Model (4) 2.2. The Copy-Modify-Merge
The Copy-Modify-Merge Model (5) Model (5)
Andy tries to Andy updates his
commit his Repository changes with the ones
changes. from the repository. Repository
Bobby The changes merge
A conflict occurs. Bobby
into his local copy.
Commit Bobby A merge conflict can
Bobby
occur. Bobby

Andy
Andy
Andy
&
Bobby
(Local
Conflict) Bobby (Local
Merge) Bobby
Andy
Andy
43
44

23 24

NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 6


1-3- Version Control 2/23/21

25 26

2.2. The Copy-Modify-Merge


The Copy-Modify-Merge Model (6)Model (6) 2.2. The Copy-Modify-Merge
The Copy-Modify-Merge Model (7) Model (7)
Andy commits the Bobby updates the
merged changes to changes from the
the repository. Repository repository. Repository
A common version Andy She gets the common Andy
with the changes of & version with both & Update
Andy and Bobby is Bobby changes from Andy Bobby
Andy
inserted. Commit Bobby
and Bobby. &
Bobby

Andy Andy
& &
Bobby Bobby

Bobby Bobby
Andy Andy
46
45

25 26

27 28

2.4. Central version control 2.5. Distributed


Distributed Version Control
Version Control
Centralized Version
• Only one Control
repository

Source: http://homes.cs.washington.edu/~mernst/advice/version-control.html 22 Source: http://homes.cs.washington.edu/~mernst/advice/version-control.html 23

27 28

NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 7


1-3- Version Control 2/23/21

29 30

Distributed Version Control (2)


Distributed
Distributed Version Version Control (1)
Control (1) Distributed Version Control (2)
Andy and Bobby
clone the remote Andy and Bobby Remote
repository locally. Remote work locally on a Repository
Repository (Server)
They both have the (Server) certain file A. A
A
same files in their
local repositories.
Clone Clone

(Local Edit)
(Local Edit) Andy Bobby
A A A A

Local Local Local Local


Repository Repository Repository Repository
(Andy) (Bobby) (Andy) (Bobby)
Andy Andy
Bobby Bobby
48
49

29 30

31 32

Distributed Version Version


Distributed Control (3)
Control (3) Distributed Version Version
Distributed Control (4)
Control (4)
Andy and Bobby Andy pushes the
commit locally the Remote
file A to the remote Remote
modified file A Repository repository. Repository
(Server) (Server)
into their local A Still no conflicts Andy
repositories. occur.
Push
Commit (locally) Commit (locally)

Andy Andy Bobby Bobby Andy Andy Bobby Bobby

Local Local Local Local


Repository Repository Repository Repository
(Andy) (Bobby) (Andy) (Bobby)
Andy Andy
Bobby Bobby
50 51

31 32

NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 8


1-3- Version Control 2/23/21

33 34

Distributed Version Version


Distributed Control (5)
Control (5) Distributed
Distributed VersionVersion
Control Control
(6) (6)
Bobby merges the
Bobby tries to push her local files with
her changes. Remote Remote
Repository the files from the
Repository
A versioning conflict (Server) remote repository. (Server)
Andy Andy
occurs. Conflicts are locally
resolved.
Push (conflict) Pull (Fetch + Merge)

Andy Andy Bobby Bobby


Andy Andy Bobby Bobby
+Andy +Andy

Local Local Local Local


Repository Repository Repository Repository
(Andy) (Bobby) (Andy) (Bobby)
Andy Andy
Bobby
Bobby 53
52

33 34

35 36

Distributed Version Control (7) Distributed VersionVersion


Control Control
(8)
Distributed Version Control (7) Distributed (8)
Andy pulls
Bobby commits her Remote (updates) the Remote
merged changes. Repository
changed files Repository
(Server) (Server)
No version conflict. Bobby
Andy from the remote Bobby
Andy
+Andy +Andy
repository.
Push (no conflict) Pull

Andy Andy Bobby Bobby Bobby Bobby Bobby Bobby


+Andy +Andy +Andy +Andy +Andy +Andy
Local Local Local Local
Repository Repository Repository Repository
(Andy) (Bobby) (Andy) (Bobby)
Andy Andy
Bobby Bobby
54 55

35 36

NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 9


1-3- Version Control 2/23/21

37 38

Outline 3. Vocabulary
1. Introduction • Repository (source control repository)
• A server that stores the files (documents)
2. Versioning Models • Keeps a change log

3. Vocabulary • Revision, Version


• Individual version (state) of a document that is a result of multiple
4. Tools changes
• Check-Out, Clone
• Retrieves a working copy of the files from a remote repository into a
local directory
• It is possible to lock the files

37 38

39 40

Vocabulary Vocabulary
• Change • Conflict
• A modification to a local file (document) that is under version • The simultaneous change to a certain file by multiple users
control • Can be solved automatically and manually
• Change Set / Change List • Update, Get Latest Version, Fetch / Pull
• A set of changes to multiple files that are going to be committed at • Download the latest version of the files from the repository to a
the same time local working directory + merge conflicting files
• Commit, Check-In • Undo Check-Out, Revert / Undo Changes
• Submits the changes made from the local working copy to the • Cancels the local changes
repository
• Restores their state from the repository
• Automatically creates a new version
• Conflicts may occur!

39 40

NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 10


1-3- Version Control 2/23/21

41 42

Vocabulary Outline
• Merge 1. Introduction
• Combines the changes to a file changed locally and simultaneously
in the repository 2. Versioning Models
• Can be automated in most cases
• Label / Tag
3. Vocabulary
• Labels mark with a name a group of files in a given version 4. Tools
• For example a release

• Branch / Branching
• Division of the repositories in a number of separate workflows

41 42

43 44

Tools What is Git?


• Central version control • Git
• SVN (Subversion) • Distributed source-control system
• TFS • Work with local and remote repositories
• Source safe (commercial) • Git bash – command line interface for Git
• Distributed version control • Free, open-source
• Git • Has Windows version (msysGit)
• http://msysgit.github.io
• Mercurial
• https://www.atlassian.com/git/tutorials/setting-up-a-repository

43 44

NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 11


1-3- Version Control 2/23/21

45 46

Installing Git Basic Git Commands


• msysGit Installation on Windows • Cloning an existing Git repository
• Download Git for Windows from: http://msysgit.github.io git clone [remote url]
• “Next, Next, Next” does the trick • Fetch and merge the latest changes from the remote
repository
• Options to select (they should be selected by default)
git pull
• “Use Git Bash only”
• “Checkout Windows-style, commit Unix-style endings”
• Preparing (adding / selecting) files for a commit
git add [filename] ("git add ."adds everything)
• Git installation on Linux:
• Committing to the local repository
sudo apt-get install git git commit –m "[your message here]"

45 46

47 48

Basic Git Commands Using Git: Example


• Check the status of your local repository (see the local mkdir work
changes) cd work
git status git clone https://github.com/SoftUni/test.git dir
• Creating a new local repository (in the current directory) cd test
git init
dir
• Creating a remote (assign a short name for remote Git
git status
URL)
git remote add [remote name] [remote url] (edit some file)
• Pushing to a remote (send changes to the remote
git status
repository) git add .
git push [remote name] [local name] git commit -m "changes"
git push

47 48

NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 12


1-3- Version Control 2/23/21

49 50

Project Hosting Sites Project Hosting Sites


• GitHub – https://github.com • Google Code – http://code.google.com/projecthosting/
• The #1 project hosting site in the world • Source control (SVN), file release, wiki, tracker
• Free for open-source projects • Very simple, basic functions only, not feature-rich
• Paid plans for private projects • Free, all projects are public and open source

• GitHub provides own Windows client • 1-minute signup, without heavy approval process

• GitHub for Windows • SourceForge – http://www.sourceforge.net


• http://windows.github.com • Source control (SVN, Git, ...), web hosting, tracker, wiki, blog,
• Dramatically simplifies Git mailing lists, file release, statistics, etc.
• For beginners only • Free, all projects are public and open source

49 50

51

Project Hosting Sites


• CodePlex – http://www.codeplex.com
• Microsoft's open source projects site
• Team Foundation Server (TFS) infrastructure
• Source control (TFS), issue tracker, downloads, discussions, wiki,
etc.
• Free, all projects are public and open source

• Bitbucket – http://bitbucket.org
• Source control (Mercurial), issue tracker, wiki, management tools
• Private projects, free and paid editions

51

NGUYỄN Thị Thu Trang, trangntt@soict.hust.edu.vn 13

You might also like