Upload
peter-chang
View
788
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
S
Version Control System
Appendix B of Introduction to C ProgrammingAuthor: Peter PH Chang
What is Version Control System?
A.k.a. 版本控制系統 目的:
個人使用: 漸進式開發使用 怕自己改爛之後改不回去本來可以動的狀況
團隊開發: 方便大家共同看一份程式碼,有效協同開發 記錄是誰、在什麼時候、因為什麼原因改了那段程式碼 Branch(分支)開發,讓支線不影響主線
Type of VCS
Copy-Paste Centralized Version Control
System Distributed Version Control
System
Type of VCS
Copy Paste The most easy way to implement Awful way No comment message Not automically Wasting space No conflict solution No duplicate for backup 不推薦使用此方法
VCS的流派 Centralized VCS
Easy to implement Learning curve is moderate Cannot develop without network Do everything by network. SLOW! There is only one server. If it is
broken, you loss everything
VCS的流派 Distributed VCS
Learning curve is steep Can work without network Everyone has its clone. Don’t
worry about server! Easy to branch!
Well-known VCS Centralized VCS
CVS Subversion (SVN) Perforce
Distributed VCS git Mercurial (Hg) Bazaar
S
Distributed VCS: git分散式版本控制系統的範例
先來用用看 環境:MS Windows
UNIX系列亦可使用,但請參考附錄文件 安裝
msysgit Windows下 git本體 http://code.google.com/p/msysgit/downloads/list?
q=net+installer TortoiseGit
git的圖形化使用者介面 http://code.google.com/p/tortoisegit/wiki/Download?tm=2
Step1Installation
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
如果你要用中文使用介面的話,可以安裝中文語言包
Step2First commit
使用流程 一開始:
利用 git init來初始化 git repo 新增檔案或修改程式碼後:
利用 git add來新增檔案到這次準備要傳到 repo的檔案 利用 git commit來把檔案呈交到 repo上
Initial Setting
先建一個資料夾,把程式碼放在裡面
Initial Setting
然後在裡面的程式碼檔案寫程式
Create a new repo
在資料夾上按右鍵,選「Git在此建立倉儲」(Git create repo )
Create a new repo
不要設為存倉儲
Create a new repo
按 Proceed,忽略該資料夾當中有其他檔案
Create a new repo
看到這個畫面就代表已經建立一個新的 Git repo
在程式碼檔案上按右鍵,選 TortoiseGit裡面的「增加」,讓他增加到這次準備要 commit的檔案中
Add file
勾選你要新增的檔案
Add file
這樣就完成add file了,但是還需要 commit才真正呈交到 repo上
Commit file
按下 Commit鍵
Commit files
若你是剛灌 git,還沒設定 name與 email的話,他會問你要不要現在設定,選 Yes來設定
Commit files
若你是剛灌 git,還沒設定 name與 email的話,他會問你要不要現在設定,選 Yes來設定
Commit files
Commit files
在「記錄訊息」裡面填寫這次Commit的修改後,就可按「確定」來Commit
Commit files
出現這個畫面就代表 Commit完成
Git diff
我們再來修改裡面的程式碼看看,在第六行加一個新的 printf
Git diff
然後在資料夾按右鍵去「 TortoiseGit」裡面選擇「比對差異」
Git diff
會出現這個視窗,顯示說現在的檔案和最後一次 Commit差在哪裡 在檔案名稱上面連點兩下,就可以詳細看檔案差異
Git diff
改爛了…怎麼改回去
改爛了…怎麼改回去
把要回復的檔案勾選起來後,按「確定」
改爛了…怎麼改回去
改好了!我們看一下那個被改過的檔案
改爛了…怎麼改回去
已經改回上一次 commit時候的狀況
Another way: CLI
新建 repo git init
新增檔案、呈交到 repo git add . git commit –m “Commit message”
查看Git記錄 git log
查看程式碼差異 git diff 5d09 git diff 5d09 ab01
S
Git Server
GitHub
可自己架 git server 在 Linux、Mac上比較好架 Windows上架 git server較為複雜
但我們有 GitHub! Easy to create public repo If you have .edu mail, you can get right to create
private repo for free during the two years https://github.com/edu
GitHub
GitHub
GitHub
複製一份下來! git clone REPO的網址 在 TortoiseGit上,新增一個資料夾按右鍵,有個 clone倉儲的按鍵,按下去之後,把 REPO的網址填入,即可自
server複製下來 和 git server溝通的方式
自 server上取得新的版本 git pull
把改好的版本送上 server git push
S
Reference
Reference
Git tutorial:http://www.slideshare.net/ihower/git-tutorial-13695342
寫給大家的 Git教學:http://www.slideshare.net/littlebtc/git-5528339
Git教學:初學者使用心得分享 (Windows) :http://www.mrmu.com.tw/2011/05/06/git-tutorial-for-beginner/