brief introduction to version control - stony brookzgao/ppt/ppt/versioncontrol.pdf · to version...

13
Brief Introduction to Version Control MERCURIAL AND GIT

Upload: buihuong

Post on 05-Oct-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Brief Introduction to Version Control - Stony Brookzgao/ppt/ppt/VersionControl.pdf · to Version Control MERCURIAL AND GIT. Version control ... Tell others about changes you have

Brief Introduction to Version Control MERCURIAL AND GIT

Page 2: Brief Introduction to Version Control - Stony Brookzgao/ppt/ppt/VersionControl.pdf · to Version Control MERCURIAL AND GIT. Version control ... Tell others about changes you have

Version controlWhat is version control?

◦ A system records changes to a file or set of files so that you can recall specific versions later

◦ Distributed and centralized

Why should we care?◦ Revert back

◦ Recover files

◦ Switch between version

◦ Collaboration

Page 3: Brief Introduction to Version Control - Stony Brookzgao/ppt/ppt/VersionControl.pdf · to Version Control MERCURIAL AND GIT. Version control ... Tell others about changes you have

Git vs Mercurial

Page 4: Brief Introduction to Version Control - Stony Brookzgao/ppt/ppt/VersionControl.pdf · to Version Control MERCURIAL AND GIT. Version control ... Tell others about changes you have

Basic terminologyRepository: working directory along with a store of the history (change set)

◦ All the operations are within the repository

◦ Local repository and remote repository

Repository: FronTier++

Working directory Change setVersion 1Version 2Version 3

……

Page 5: Brief Introduction to Version Control - Stony Brookzgao/ppt/ppt/VersionControl.pdf · to Version Control MERCURIAL AND GIT. Version control ... Tell others about changes you have

How to create a repositoryOperations Mercurial Git

Step1:Configure username

Add lines in ~/.hgrc

[ui]

username = Zheng Gao <[email protected]>

$ git config --global user.name “Zheng Gao“$ git config --global [email protected]

Step 2: Initialize hg init git init

Step 3: add files hg add . git add .

Step 4: commit hg commit git commit

Page 6: Brief Introduction to Version Control - Stony Brookzgao/ppt/ppt/VersionControl.pdf · to Version Control MERCURIAL AND GIT. Version control ... Tell others about changes you have

Fork and CloneFork: make a copy on Github

Clone: copy the repository to local computer

Page 7: Brief Introduction to Version Control - Stony Brookzgao/ppt/ppt/VersionControl.pdf · to Version Control MERCURIAL AND GIT. Version control ... Tell others about changes you have

BranchBranch: a way to keep the line of development separate

Default branch is “master”

Page 8: Brief Introduction to Version Control - Stony Brookzgao/ppt/ppt/VersionControl.pdf · to Version Control MERCURIAL AND GIT. Version control ... Tell others about changes you have

Commits relatedCommits: Logical chunks of changes saved in sequence (time stamp, commit message, author, hash, change set)

◦ example: To save your changes: hg commit or git commit

Tags: name for each commit, latest is HEAD ◦ example : To tag your commit with ver1.1: git tag ver1.1 or hg tag ver 1.1

Checkout/Update: switch between branch or commits

Example: to checkout old version: git checkout version_hash or hg update –r version_number

Checkout/Revert: revert files to earlier revision

Example: to revert a file to old version: hg revert –r <rev> file or gitcheckout <rev> --filename

Page 9: Brief Introduction to Version Control - Stony Brookzgao/ppt/ppt/VersionControl.pdf · to Version Control MERCURIAL AND GIT. Version control ... Tell others about changes you have

Pull/Fetch and Update/MergePull: keep sync with other repositories

In hg, go to your project and type◦ $hg pull

◦ $hg update

In git, just use pull = fetch + merge◦ $git pull

Fetch: fetch change set from other repositories◦ $git fetch

Merge: combine changes from two places, resolve conflicts manually

Page 10: Brief Introduction to Version Control - Stony Brookzgao/ppt/ppt/VersionControl.pdf · to Version Control MERCURIAL AND GIT. Version control ... Tell others about changes you have

Push and Pull requestPush: push branches to other repository where you have access permission

Pull request: Tell others about changes you have pushed on Github

Page 11: Brief Introduction to Version Control - Stony Brookzgao/ppt/ppt/VersionControl.pdf · to Version Control MERCURIAL AND GIT. Version control ... Tell others about changes you have

Work Flow without GitHub

Pull

Push

Remote repository

Zheng’s repository

Changeset

Commit

Update

Page 12: Brief Introduction to Version Control - Stony Brookzgao/ppt/ppt/VersionControl.pdf · to Version Control MERCURIAL AND GIT. Version control ... Tell others about changes you have

Work with GitHub

FronTier in GitHub Zheng’s GitHub

Zheng’s local computer

Pull/ClonePush

Merge

Branch Add new featureFix bugs

Send a pull request

Accept

Pull

Page 13: Brief Introduction to Version Control - Stony Brookzgao/ppt/ppt/VersionControl.pdf · to Version Control MERCURIAL AND GIT. Version control ... Tell others about changes you have

hg vs githg git

hg clone git clone

hg status git status

hg add git add

hg commit git commit

hg push git push

hg pull git fetch

hg update git merge

hg revert git checkout

hg pull –update git pull

hg diff git diff

hg remove git rm

Hope it’s usefulThank you