Version Control System Git zswu Computer Center CS
- Slides: 40
Version Control System - Git zswu
Computer Center, CS, NCTU 2 Overview q Why VCS ? q Why Git ? q Using Git Personally q Using Git with Others q Etiquette Rules of Using Git q Tools & Services q Tips
Computer Center, CS, NCTU 3 Why VCS (1/3) q How do you manage your homework ?
Computer Center, CS, NCTU 4 Why VCS (2/3) q How the people do version control ? • Share files with CD, USB or Network • Patch q What is the problem ? • Many different version • Hard to maintaining, debugging
Computer Center, CS, NCTU 5 Why VCS (3/3) q A tool help you manage you project • • Commit, Rollback, Checkout Branch, Tag Merge Clone, Push, Pull q Common VCS • • • CVS RCS SVN … Git
Computer Center, CS, NCTU Git q Not a software only for you to download code from Github q Distributed revision control system (DVCS) • P 2 P instead of Client-Server • No Trunk (主幹) • Fast Ø Everything is at local, no need to sync with server • Convenient Ø You can easily create branch without modify the server side repository 6
Computer Center, CS, NCTU Using Git Personally q Base version control • • Init Status Add, Commit Reset q View history • Log • Blame q Develop different feature • Branch, Tag, Checkout • Rebase, Merge 7
Computer Center, CS, NCTU Config q You need to add basic config before using git • Position Ø Global (~/. gitconfig) Ø Local (project-root/. gitconfig) Ø System (/etc/gitconfig) • Basic config Ø $ git config --global user. name “zswu“ Ø $ git config --global user. email zswu@cs. nctu. edu. tw • Other config Ø core. editor vim Ø merge. tool vimdiff 8
Computer Center, CS, NCTU 9 Init q Init a empty local repository • Create a. git directory, everything about version control is inside this directory
Computer Center, CS, NCTU 10 Status q Show the status • • Untracked files Modified files Deleted files Intermediately state Ø Rebase Ø Merge
Computer Center, CS, NCTU 11 Add q Add files to the temporary area (to be commited) • You don’t need to commit all the thing at the same time • Use. gitignore file to prevent some files to be added
Computer Center, CS, NCTU 12 Commit q Save your current state • • Has a hash ID Which hash ID is the previous state What you modified Write some log to help people know what have you done
Computer Center, CS, NCTU 13 Reset q Reset a commit or reset temporary area • If you regret, you can remove all change from temporary area, or remove a commit • HEAD^ / HEAD~1, the previous commit of HEAD • https: //gitbook. tw/chapters/using-git/reset-commit. html
Computer Center, CS, NCTU 14 Log q List history of the repository • Commit message • Commit Hash ID • Commit author
Computer Center, CS, NCTU 15 Blame q History of a file • Show the latest commit of each line • To find who added this line into your code
Computer Center, CS, NCTU 16 Branch q Work on multiple thing at the same time • Add feature or debug individually • Keep master branch stable
Computer Center, CS, NCTU 17 Tag q Tag specific commit • Release commit, e. g. , v 1. 0. 1, v 1. 2. 3 rc, v 2. 5 b 3 • Tag point to only one commit
Computer Center, CS, NCTU 18 Checkout q Checkout something • Branch, Tag • Commit (by Hash ID)
Computer Center, CS, NCTU 19 Merge q Merge branch B to branch A • If B is based on A, Fast-forward is applied • If both A and B is changed, a merge commit is added • If auto merge failed, you need to solve the conflict yourself
Computer Center, CS, NCTU 20 Rebase q Rebase branch B onto branch A • Add each commit of branch B onto branch A • No merge commit • If you branch B is forked from branch A, you can use rebase to apply the latest branch A commits
Computer Center, CS, NCTU Using Git with Others q Remote repository • • • Clone Remote Fetch Push Pull => Fetch + Merge 、Fetch + Rebase q Conflict • Rebase/Merge --about/--skip/--continue • Stash / Stash pop • Revert 21
Computer Center, CS, NCTU 22 Clone q Clone a git repository • Copy all things including history, branch, tag
Computer Center, CS, NCTU 23 Remote q About remote repository • You can add many remote repository • Usually, origin is your default remote repository
Computer Center, CS, NCTU 24 Fetch q Fetch new commits from remote • Remote branch will be placed at remote-name/branch-name Ø origin/master Ø origin/debug 1 • Usually, we will do this after fetch Ø $ git rebase origin/master
Computer Center, CS, NCTU 25 Push q Push things to remote branch • You must have write permission on remote server • Push a branch to remote Ø If exist, update it
Computer Center, CS, NCTU 26 Pull q Pull is equal to fetch + merge, or fetch + rebase • Defaults to fetch + merge • Pull something add a lots of marge message into your project Ø Use fetch + rebase instead
Computer Center, CS, NCTU 27 Conflict q Why • Modify same file Ø Auto merge failed • Squash commits Ø Squash will change commits history • $ git push -f Ø Try to not do this
Computer Center, CS, NCTU 28 Merge/Rebase Conflict q Continue • After you fixed the conflict, continue the action (Merge/Rebase) q Skip • Skip this commit, it won’t be merge into target branch q Abort • Abort, nothing will change
Computer Center, CS, NCTU 29 Stash / Stash Pop q Stash things not yet commit • Like a stack, first in last out • Convenient when rebasing/merging
Computer Center, CS, NCTU 30 Revert q Revert a commit • Revert a commit by adding a new commit Ø Won’t break the history • The new commit offset the old one
Computer Center, CS, NCTU Etiquette Rules of Using Git (1/5) q Commit Message • • • What you done Why How Format is important $ git rebase -i HEAD~x q Don’t modify master directly • Master branch may become unstable • Others need to solve the conflict that cause by your temporary code • To keep history clean 31
Computer Center, CS, NCTU Etiquette Rules of Using Git (2/5) q Keep history clean • Don’t change the history if you share branch with others Ø A lots of conflicts • Try to not use $ git push -f Ø A lots of conflicts • Try to not use merge (use reabase), except you are on master branch Ø Branch may become incapable of being merge • Try to not do $ git pull (fetch + merge) Ø Will add unnecessary merge commit • Use rebase -i Ø Rewrite your history 32
Computer Center, CS, NCTU 33 Etiquette Rules of Using Git (3/5) q Good commit message
Computer Center, CS, NCTU 34 Etiquette Rules of Using Git (4/5) q Bad commit message
Computer Center, CS, NCTU 35 Etiquette Rules of Using Git (5/5) q Use rebase -i to create clean history • $ git rebase -i HEAD~10
Computer Center, CS, NCTU Tools & Services (1/2) q Online Git Service • • Web interface Remote repository Issue, Pull Requests (or Merge Requests… etc. ) Code Review Community CI/CD Example Ø Git. Hub Ø Git. Lab Ø Bitbucket 36
Computer Center, CS, NCTU Tools & Services (2/2) q Tools • Gerrit Ø Web-based code review tool • Tig Ø ncurses-based text-mode interface for Git Ø https: //www. jianshu. com/p/e 4 ca 3030 a 9 d 5 • Git GUI Ø GUI-based interface for Git • KDiff 3 / vimdiff / meld Ø Help users to solve conflict • etc. 37
Computer Center, CS, NCTU Tips (1/3) q Conflict Solving • Use merge tools Ø $ git config --global merge. tool kdiff 3 • Show common ancestor Ø $ git config --global merge. conflictstyle diff 3 • Change merge algorithm Ø $ git merge --strategyoption=patience • More. . . Ø https: //developer. atlassian. com/blog /2015/12/tips-tools-to-solve-gitconflicts/ 38
Computer Center, CS, NCTU 39 Tips (2/3) q History visualize • Use git log Ø $ git log --decorate --graph [--oneline] Ø $ git log --graph --abbrev-commit -decorate --format=format: '%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all Ø $ man git-log
Computer Center, CS, NCTU 40 Tips (3/3) q History visualize (cont. ) • Git. Hub / Online tools • Git GUI
- Git clone git://git.drogon.net/wiringpi
- Zswu
- Versionhallinta git
- Version control systems industry
- Tortoise svn tutorial
- Configuration management version control
- Introduction to git ppt
- Version control branching
- Alienbrain version control
- Version control powerpoint
- Git powerpoint
- Power system control center
- Ursv2
- Climate forecast system version 2
- Cvs versioning system
- Cfsv
- Objective of computer system
- What is computer organization
- Control mass in thermodynamics
- Install git jupyter notebook
- Unity team collaboration
- Git
- Git hub io
- Bts tourisme coefficient
- Rapidjson object to string
- Flora git
- Git file lifecycle
- Git flic
- Rebase vs merge git
- Gitscm.com
- Rebase branch onto master
- Set properties globally git
- Git global name
- Corpus adiposum buccae
- Recessus retrocaecalis
- Intestinal structure
- Glo gli git
- Git organs
- Whats git hub
- Git distributed
- Git distributed