1 of 31

Introduction to �Version Control System

​

Kwanghoon Choi

Chonnam National University

1

2 of 31

Motivation

  • Without version control system(VCS), you
    • Make a single backup copy
    • Add a version number or date, and
    • Use a shared folder so other people can see and edit files together

2

KalidAzadResumeOct2014.doc

KalidAzadResumeMar2015.doc

…

Instacalc-logo3.png

Instacalc-logo4.png

…

time

3 of 31

Table of Contents

  • Version Control System (VCS)
  • Distributed Version Control
  • Git

3

4 of 31

Version Control System (VCS)

  • Track your files over time so that you can easily get back to a previous working version

​

  • VCS software
    • CVS (Concurrent Version System)
    • SVN (Subversion)
    • Mercurial
    • Darcs
    • Git

​

  • Repository or Repo (저장소)

4

5 of 31

General Actions in VCS: Checkin

  • Check in a file(list.txt) and modify it over time

​

5

(*) Trunk (in SVN), Branch (in Git) : The location for code in the repo.

(*) check in (in SVN), commit (in Git)

6 of 31

Checkout and editing

  • Check out, edit, and check in a file(list.txt)

​

6

(*) Trunk (in SVN), Branch (in Git) : The location for code in the repo.

(*) check out (in SVN), fetch/pull (in Git)

7 of 31

Diffs

  • The trunk has a history of changes as a file evolves.

​

7

(*) Trunk (in SVN), Branch (in Git) : The location for code in the repo.

8 of 31

Branching

  • Copy code into a separate folder so we can have a separate history of changes

​

8

(*) Trunk (in SVN), Branch (in Git) : The location for code in the repo.

9 of 31

Merging

  • Merge changes from one branch to another

​

9

(*) Trunk (in SVN), Branch (in Git) : The location for code in the repo.

R8 has a merge of Bread from r7 Rice from r6.

10 of 31

Conflicts

  • When changes overlap like an example below

​

10

(*) Trunk (in SVN), Branch (in Git) : The location for code in the repo.

  1. Joe and Sue check out the same revision r3 into his or her local copy, respectively.
  2. Joe changes –Eggs and +Cheese.
  3. Sue changes –Eggs and +Hot Dog.
  4. Joe check in his change to make a new revision r4.
  5. Sue cannot check in her change because of a conflict.

1

1

2

3

4

5

11 of 31

Conflicts (cont.) : How to resolve?

  • Two options by Sue
    • Re-apply your changes (r4 +Hot Dog)
    • Override their changes with yours (r4 -Cheese, +HotDog)

​

11

(*) Trunk (in SVN), Branch (in Git) : The location for code in the repo.

12 of 31

Tagging

  • Let you tag (label) any revision for easy reference such as ‘Release 1.0’ instead of r4

​

12

(*) Trunk (in SVN), Branch (in Git) : The location for code in the repo.

13 of 31

Real-Life Example

  • Managing Windows: Integrating Media Player (MP) 11 and Internet Explorer (IE) 7 into Windows
    • Forward integration (FI)
    • Reverse integration (RI)

​

13

(*) Trunk (in SVN), Branch (in Git) : The location for code in the repo.

14 of 31

Two Main Types of VCS

  • Centralized VCS
    • One central repository with many users

​

    • E.g., CVS, SVN

​

  • Decentralized (Distributed) VCS
    • Every user owns his or her local repository
    • A separate remote (central) repository
      • Sometimes, more than one remote (central) repositories

​

    • Two new actions (with remote repositories): fork pull request

​

    • E. g., GIT, Mercurial, Darcs

14

15 of 31

Introduction to GIT

  • Linus Torvalds
    • For collaboration of development of Linux kernel
  • A distributed version control system
    • Workspace : files you are working with
    • Index: (staged) files to be considered in the next commit
    • Local repository : files committed to the local repo
    • Remote repository : files pushed to the remote repo

​

15

Local

Repository

Remote

Repository

Index

(Stage)

Workspace

(Working

Directory)

Local Computer

Remote Computer

16 of 31

Introduction to GIT: Workflow

16

Local

Repository

Remote

Repository

Index

(Stage)

Workspace

(Working

Directory)

Local

Computer

Remote

Computer

git clone

17 of 31

Introduction to GIT: Workflow

17

Local

Repository

Remote

Repository

Index

(Stage)

Workspace

(Working

Directory)

Local

Computer

Remote

Computer

git add

18 of 31

Introduction to GIT: Workflow

18

Local

Repository

Remote

Repository

Index

(Stage)

Workspace

(Working

Directory)

Local

Computer

Remote

Computer

git add

git commit

19 of 31

Introduction to GIT: Workflow

19

Local

Repository

Remote

Repository

Index

(Stage)

Workspace

(Working

Directory)

Local

Computer

Remote

Computer

git add

git commit

git commit –a

20 of 31

Introduction to GIT: Workflow

20

Local

Repository

Remote

Repository

Index

(Stage)

Workspace

(Working

Directory)

Local

Computer

Remote

Computer

git add

git commit

git commit –a

git push

21 of 31

Introduction to GIT: Workflow

21

Local

Repository

Remote

Repository

Index

(Stage)

Workspace

(Working

Directory)

Local

Computer

Remote

Computer

git add

git commit

git commit –a

git push

git fetch

22 of 31

Introduction to GIT: Workflow

22

Local

Repository

Remote

Repository

Index

(Stage)

Workspace

(Working

Directory)

Local

Computer

Remote

Computer

git add

git commit

git commit –a

git push

git fetch

git merge

23 of 31

Introduction to GIT: Workflow

23

Local

Repository

Remote

Repository

Index

(Stage)

Workspace

(Working

Directory)

Local

Computer

Remote

Computer

git add

git commit

git commit –a

git push

git fetch

git merge

git pull

24 of 31

Introduction to GIT: Workflow

24

Local

Repository

Remote

Repository

Index

(Stage)

Workspace

(Working

Directory)

Local

Computer

Remote

Computer

git add

git commit

git commit –a

git push

git fetch

git merge

git pull

git diff HEAD

25 of 31

Introduction to GIT: Workflow

25

Local

Repository

Remote

Repository

Index

(Stage)

Workspace

(Working

Directory)

Local

Computer

Remote

Computer

git add

git commit

git commit –a

git push

git fetch

git merge

git pull

git diff HEAD

git diff

26 of 31

Introduction to GIT: Workflow

26

My Repository

OSS Repository

pull request

fork

27 of 31

GitHub

  • Git-based Source Code Hosting for Social Coding
  • Fork, Pull request, Code review facilities, …

27

fork

Pull request

28 of 31

[실습1]

  • Collaboration (1st interaction)
  • https://github.com/kwanghoon/oss_git_example을 fork하여 본인의 원격 저장소를 만들고 이를 로컬 저장소로 가져와 수정한 다음 다시 올린 다음 kwanghoon의 oss_git_example에 pull request

​

​

28

순희.txt

철수.txt

kwanghoon/oss_git_example

순희.txt

soonnhee/oss_git_example

철수.txt

cheolsoo/oss_git_example

29 of 31

[실습2]

  • Collaboration (after the 1st interaction)
  • 철수와 순희가 각각 pull request한 내용을 본인들도 모두 내려받으려면 어떻게 할까?

​

​

29

순희.txt

철수.txt

kwanghoon/oss_git_example

순희.txt

철수.txt

soonnhee/oss_git_example

순희.txt

철수.txt

cheolsoo/oss_git_example

30 of 31

GitHub Social Coding

  • Collaboration (after the 1st interaction)

$ git remote add pb https://github.com/kwanghoon/oss_git_example

$ git fetch pb

$ git diff pb/master ( cf. resolve conflicts if there are any )

$ git rebase pb/master

$ git commit -a -m “merge 3rd party contributions”

$ git push origin

30

31 of 31

Reference

​

31