Brief Introduction to Version Control MERCURIAL AND GIT
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
Git vs Mercurial
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
……
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
Fork and CloneFork: make a copy on Github
Clone: copy the repository to local computer
BranchBranch: a way to keep the line of development separate
Default branch is “master”
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
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
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
Work Flow without GitHub
Pull
Push
Remote repository
Zheng’s repository
Changeset
Commit
Update
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
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