Version Control System
    Appendix B of Introduction to C Programming
             Author: Peter PH Chang




                                                  S
What is Version Control System?


S A.k.a. 版本控制系統

S 目的:
 S 個人使用:
   S 漸進式開發使用
   S 怕自己改爛之後改不回去本來可以動的狀況
 S 團隊開發:
   S 方便大家共同看一份程式碼,有效協同開發
   S 記錄是誰、在什麼時候、因為什麼原因改了那段程式碼
   S Branch(分支)開發,讓支線不影響主線
Type of VCS


S Copy-Paste
S Centralized Version Control System
S Distributed Version Control System
Type of VCS

S Copy Paste
 S   The most easy way to implement
 S   Awful way
 S   No comment message
 S   Not automically
 S   Wasting space
 S   No conflict solution
 S   No duplicate for backup
 S   不推薦使用此方法
VCS的流派

S Centralized VCS
 S Easy to implement
 S Learning curve is moderate
 S Cannot develop without network
 S Do everything by network. SLOW!
 S There is only one server. If it is
   broken, you loss everything
VCS的流派

S Distributed VCS
 S Learning curve is steep
 S Can work without network
 S Everyone has its clone. Don’t worry
   about server!
 S Easy to branch!
Well-known VCS
S Centralized VCS
 S CVS
 S Subversion (SVN)
 S Perforce
S Distributed VCS
 S git
 S Mercurial (Hg)
 S Bazaar
Distributed VCS: git
   分散式版本控制系統的範例




                       S
先來用用看


S 環境:MS Windows
 S UNIX系列亦可使用,但請參考附錄文件

S 安裝
 S msysgit
   S   Windows下git本體
   S   http://code.google.com/p/msysgit/downloads/list?q=net+installer
 S TortoiseGit
   S   git的圖形化使用者介面
   S   http://code.google.com/p/tortoisegit/wiki/Download?tm=2
Step1
Installation
Install msysgit - 1
Install msysgit - 2




會看到上面這個安裝檔,點兩下執行即可
Install msysgit - 4




   一直按Next即可安裝
Install msysgit - 5
Install msysgit - 6




 出現這個畫面就代表安裝完畢
Install Tortoise git - 1




                   看你是32-bit還是64-bit
                   選一個下載




               語言包,安裝完主程式
               之後可以安裝語言包讓
               介面變中文
Install Tortoise git - 2




會看到上面這個安裝檔,點兩下執行即可
Install Tortoise git - 3




     一直按Next即可安裝
Install Tortoise git - 4




有時候會跳出類似這個的警告視窗,按「是」即可繼續安裝
Install Tortoise git - 5




    看到這個畫面代表安裝完畢
Install Tortoise git - 6




如果你要用中文使用介面的話,可以安裝中文語言包
Step2
First commit
使用流程


S 一開始:
 S 利用git init來初始化git repo

S 新增檔案或修改程式碼後:
 S 利用git add來新增檔案到這次準備要傳到repo的檔案
 S 利用git commit來把檔案呈交到repo上
Initial Setting


S 先建一個資料夾,把程式碼放在裡面
Initial Setting


S 然後在裡面的程式碼檔案寫程式
Create a new repo

S 在資料夾上按右鍵,選「Git在此建立倉儲」(Git create repo )
Create a new repo

S 不要設為存倉儲
Create a new repo

S 按Proceed,忽略該資料夾當中有其他檔案
Create a new repo

S 看到這個畫面就代表已經建立一個新的Git repo
在程式碼檔案上按右鍵,
選TortoiseGit裡面的
「增加」,讓他增加到
這次準備要commit的檔
案中
Add file

S 勾選你要新增的檔案
Add file

S 這樣就完成add file了,但是還需要commit才真正呈交到repo上
Commit file

S 按下Commit鍵
Commit files

S 若你是剛灌git,還沒設定name與email的話,他會問你要不要現
 在設定,選Yes來設定
Commit files

S 若你是剛灌git,還沒設定name與email的話,他會問你要不要現
 在設定,選Yes來設定
Commit files
Commit files




S 在「記錄訊息」裡面填寫這次Commit的修改後,就可按「確定」來
 Commit
Commit files




S 出現這個畫面就代表Commit完成
Git diff




S 我們再來修改裡面的程式碼看看,在第六行加一個新的printf
Git diff




S 然後在資料夾按右鍵去「TortoiseGit」裡面選擇「比對差異」
Git diff




S 會出現這個視窗,顯示說現在的檔案和最後一次Commit差在哪裡

S 在檔案名稱上面連點兩下,就可以詳細看檔案差異
Git diff
改爛了…怎麼改回去
改爛了…怎麼改回去




S 把要回復的檔案勾選起來後,按「確定」
改爛了…怎麼改回去




S 改好了!我們看一下那個被改過的檔案
改爛了…怎麼改回去




S 已經改回上一次commit時候的狀況
Another way: CLI

S 新建repo
  S git init

S 新增檔案、呈交到repo
  S git add .
  S git commit –m “Commit message”

S 查看Git記錄
  S git log

S 查看程式碼差異
  S git diff 5d09
  S git diff 5d09 ab01
Git Server




             S
GitHub


S 可自己架git server
  S 在Linux、Mac上比較好架
  S Windows上架git server較為複雜

S 但我們有GitHub!
  S Easy to create public repo
  S If you have .edu mail, you can get right to create private
     repo for free during the two years
     S   https://github.com/edu
GitHub
GitHub
GitHub

S 複製一份下來!
 S git clone REPO的網址
 S 在TortoiseGit上,新增一個資料夾按右鍵,有個clone倉儲的
   按鍵,按下去之後,把REPO的網址填入,即可自server複製
   下來

S 和git server溝通的方式
 S 自server上取得新的版本
   S   git pull
 S 把改好的版本送上server
   S   git push
Reference




            S
Reference


S Git tutorial:http://www.slideshare.net/ihower/git-tutorial-
  13695342

S 寫給大家的Git教學:http://www.slideshare.net/littlebtc/git-
  5528339

S Git教學:初學者使用心得分享(Windows) :
  http://www.mrmu.com.tw/2011/05/06/git-tutorial-for-
  beginner/

Introduction to Version Control System for Windows