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

Introduction to Version Control System for Windows

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Introduction to Version Control System for Windows

S

Version Control System

Appendix B of Introduction to C ProgrammingAuthor: Peter PH Chang

Page 2: Introduction to Version Control System for Windows

What is Version Control System?

A.k.a. 版本控制系統 目的:

個人使用: 漸進式開發使用 怕自己改爛之後改不回去本來可以動的狀況

團隊開發: 方便大家共同看一份程式碼,有效協同開發 記錄是誰、在什麼時候、因為什麼原因改了那段程式碼 Branch(分支)開發,讓支線不影響主線

Page 3: Introduction to Version Control System for Windows

Type of VCS

Copy-Paste Centralized Version Control

System Distributed Version Control

System

Page 4: Introduction to Version Control System for Windows

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 不推薦使用此方法

Page 5: Introduction to Version Control System for Windows

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

Page 6: Introduction to Version Control System for Windows

VCS的流派 Distributed VCS

Learning curve is steep Can work without network Everyone has its clone. Don’t

worry about server! Easy to branch!

Page 7: Introduction to Version Control System for Windows

Well-known VCS Centralized VCS

CVS Subversion (SVN) Perforce

Distributed VCS git Mercurial (Hg) Bazaar

Page 8: Introduction to Version Control System for Windows

S

Distributed VCS: git分散式版本控制系統的範例

Page 9: Introduction to Version Control System for Windows

先來用用看 環境: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

Page 10: Introduction to Version Control System for Windows

Step1Installation

Page 11: Introduction to Version Control System for Windows

Install msysgit - 1

Page 12: Introduction to Version Control System for Windows

Install msysgit - 2

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

Page 13: Introduction to Version Control System for Windows

Install msysgit - 4

一直按 Next即可安裝

Page 14: Introduction to Version Control System for Windows

Install msysgit - 5

Page 15: Introduction to Version Control System for Windows

Install msysgit - 6

出現這個畫面就代表安裝完畢

Page 16: Introduction to Version Control System for Windows

Install Tortoise git - 1

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

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

Page 17: Introduction to Version Control System for Windows

Install Tortoise git - 2

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

Page 18: Introduction to Version Control System for Windows

Install Tortoise git - 3

一直按 Next即可安裝

Page 19: Introduction to Version Control System for Windows

Install Tortoise git - 4

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

Page 20: Introduction to Version Control System for Windows

Install Tortoise git - 5

看到這個畫面代表安裝完畢

Page 21: Introduction to Version Control System for Windows

Install Tortoise git - 6

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

Page 22: Introduction to Version Control System for Windows

Step2First commit

Page 23: Introduction to Version Control System for Windows

使用流程 一開始:

利用 git init來初始化 git repo 新增檔案或修改程式碼後:

利用 git add來新增檔案到這次準備要傳到 repo的檔案 利用 git commit來把檔案呈交到 repo上

Page 24: Introduction to Version Control System for Windows

Initial Setting

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

Page 25: Introduction to Version Control System for Windows

Initial Setting

然後在裡面的程式碼檔案寫程式

Page 26: Introduction to Version Control System for Windows

Create a new repo

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

Page 27: Introduction to Version Control System for Windows

Create a new repo

不要設為存倉儲

Page 28: Introduction to Version Control System for Windows

Create a new repo

按 Proceed,忽略該資料夾當中有其他檔案

Page 29: Introduction to Version Control System for Windows

Create a new repo

看到這個畫面就代表已經建立一個新的 Git repo

Page 30: Introduction to Version Control System for Windows

在程式碼檔案上按右鍵,選 TortoiseGit裡面的「增加」,讓他增加到這次準備要 commit的檔案中

Page 31: Introduction to Version Control System for Windows

Add file

勾選你要新增的檔案

Page 32: Introduction to Version Control System for Windows

Add file

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

Page 33: Introduction to Version Control System for Windows

Commit file

按下 Commit鍵

Page 34: Introduction to Version Control System for Windows

Commit files

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

Page 35: Introduction to Version Control System for Windows

Commit files

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

Page 36: Introduction to Version Control System for Windows

Commit files

Page 37: Introduction to Version Control System for Windows

Commit files

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

Page 38: Introduction to Version Control System for Windows

Commit files

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

Page 39: Introduction to Version Control System for Windows

Git diff

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

Page 40: Introduction to Version Control System for Windows

Git diff

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

Page 41: Introduction to Version Control System for Windows

Git diff

會出現這個視窗,顯示說現在的檔案和最後一次 Commit差在哪裡 在檔案名稱上面連點兩下,就可以詳細看檔案差異

Page 42: Introduction to Version Control System for Windows

Git diff

Page 43: Introduction to Version Control System for Windows

改爛了…怎麼改回去

Page 44: Introduction to Version Control System for Windows

改爛了…怎麼改回去

把要回復的檔案勾選起來後,按「確定」

Page 45: Introduction to Version Control System for Windows

改爛了…怎麼改回去

改好了!我們看一下那個被改過的檔案

Page 46: Introduction to Version Control System for Windows

改爛了…怎麼改回去

已經改回上一次 commit時候的狀況

Page 47: Introduction to Version Control System for Windows

Another way: CLI

新建 repo git init

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

查看Git記錄 git log

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

Page 48: Introduction to Version Control System for Windows

S

Git Server

Page 49: Introduction to Version Control System for Windows

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

Page 50: Introduction to Version Control System for Windows

GitHub

Page 51: Introduction to Version Control System for Windows

GitHub

Page 52: Introduction to Version Control System for Windows

GitHub

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

server複製下來 和 git server溝通的方式

自 server上取得新的版本 git pull

把改好的版本送上 server git push

Page 53: Introduction to Version Control System for Windows

S

Reference

Page 54: Introduction to Version Control System for Windows

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/