CSCI4140 2 - Version-Control
CSCI4140 2 - Version-Control
https://course.cse.cuhk.edu.hk/~csci4140/
2
Why Version Control? (Cont.)
• Scenario 2 (individual):
- It still breaks
- What’s wrong?
3
Why Version Control? (Cont.)
• Scenario 3 (individual):
4
Why Version Control? (Cont.)
• Scenario 4 (team):
- rsync
5
Why Version Control? (Cont.)
• Scenario 5 (team):
• Scenario 6 (team):
7
Solution: Version Control
• You use version control in many softwares
- Check out: fetching a copy of a file from the repository to your local
.
workspace Download
- Update: fetching copies of the latest version of all files that have
been committed by other users
9
心
Repository Location
• A repository can be created on your local machine or on
a remote server
10
History of Files
CommitsHistory
- Supports undo
- Implies backups
- Explains rationale
[ 和 nashcid
中 12
Which Files to Manage?
• All source code and resource files (plain-text files are
preferred)
- C/C++/Java/HTML code
- Build/Configuration files
- Documentation
- Accidental overwriting
• Common strategies A
14
生
!!
Change Conflicts
Problem that may happen
Repository
Repository
F
F
F’ F’’
F F Alice Bob
Alice Bob
Two users read the same file They edit their own copies
Repository Repository
F’ F’’
F’ F’’ F’ F’’
Alice Bob Alice Bob
Alice publishes her copy first Bob publishes his copy later
15
Applying locktosolvethe poblem
Locking Files
Repository Repository
F F
F F
Alice Bob Alice Bob
Alice locks and reads file F Bob fails to acquire the lock, while Alice edits
Repository Repository
F’ F’
F’ F’ F’
Alice Bob Alice Bob
Alice publishes her copy and releases the lock Bob can lock and edit the latest version
16
Problems Regarding Locking
• How to lock?
• When to unlock?
- Manual release
17
Detecting Conflicts
Repository
Repository
F
F
F’ F’’
F F Alice Bob
Alice Bob
Two users read the same file They edit their own copies
Repository Repository
F’ F’
F’ F’’ F’ F’’
Alice Bob Alice Bob
Alice publishes her copy first Bob gets a conflict error
18
Resolving Conflicts
Repository
Repository
F’
F’
F’ F*
F’ F’’ F’ Alice Bob
Alice Bob
Bob compares the latest version to his own Bob creates a new merged version
Repository Repository
F* F*
F’ F* F* F*
Alice Bob Alice Bob
Bob publishes the merged version Alice also gets Bob’s change now
19
Resolving Conflicts - Merging
• Merging is required if there are conflicts on changes of the same file
• User intervention is required if the changes on the same file are overlapping
- The VCS shows the difference between two changes and asks the user
to manually repair the conflict
20
Branches
Checkout
• Branches can be
- Developed independently
- Merged later
22
Branches (Cont.)
• Branches per Release
_ Coumit
↓
Changesbetween
Commit了
https://blog.codinghorror.com/software-branching-and-parallel-universes/
23
Branches (Cont.)
• Branches per Component 構成要素 ,
零件
https://blog.codinghorror.com/software-branching-and-parallel-universes/
24
Semantic Versioning for Releases lapublish & renameaversion
H
boolean Arelase
→ number IOS / 3 14 (
_
迥
1 2
. .
candowngrade
1 . 00 有 bug
25
Classes of Version Control Systems
• Local version control @
26
自
自
己
己
Centralized VCS
• A central master server maintains the “official copy”
of the files
-
S → Commit → C
28
Distributed VCS
local & cantral
30
Distributed Versions of Git
• Each modification to the central repository increments the version number
of the overall repository in Subversion
与
commit 1235a8afaf3939b77bc6f596ea03f2be249c4145
Author: Wei Meng <[email protected]>
Date: Thu Oct 26 17:07:29 2017 +0800
commit 42f9f85437e7805886cac3ee260bd7eab9836237
Author: Wei Meng <[email protected]>
Date: Thu Oct 19 19:37:42 2017 +0800
~
hashed filenames
ㄈㄧ
A commit tree
-
l
- Checked out and modified, but not yet committed (working copy)
- In a “staging area”
Commit
35
Basic Git Workflow
• Add new files to be tracked
38
Git Branches - HEAD Pointer
od auw
timeline
>
maser HEAD = C4
:
2 branches
A merge commit
C 3 對 clint branch
冇廷們作
延伸fomservrbraum ( c 3 )
mastw brmdh
( Xchange C 3 )
- You can set up your own server that speaks the Git protocol to host
repositories
47
Learn More About Git
• 1st Tutorial Session
48