vsts-git with visual studio 入門教學

55
VSTS – GIT WITH VISUAL STUDIO WORKSHOP 陳陳陳 , BRUCE CHEN HTTPS://KKBRUCE.TW HTTP://BLOG.KKBRUCE.NET

Upload: bruce-chen

Post on 09-Jan-2017

1.282 views

Category:

Software


0 download

TRANSCRIPT

Page 1: VSTS-Git with Visual Studio 入門教學

VSTS – GIT WITH VISUAL STUDIOWORKSHOP

陳傳興 , BRUCE CHEN

HTTPS://KKBRUCE.TW

HTTP://BLOG.KKBRUCE.NET

Page 2: VSTS-Git with Visual Studio 入門教學

VISUAL STUDIO TEAM SERVICES

• https://www.visualstudio.com/products/visual-studio-team-services-vs

• 個人均可免費申請使用。• 5 人以下團隊免費使用。

Page 3: VSTS-Git with Visual Studio 入門教學

GIT AND GITHUB

• Git 是分散式 Version Control 軟體• Github 以 git 為基礎擴充的伺服器服務,使專案更便於協作與發佈• VSTS 支援 Git 版控

Page 4: VSTS-Git with Visual Studio 入門教學

GIT 2.7.4

• Git for Windows 2.7.4 之前含一個重大漏洞 ( http://mvc.tw/004N ) ,請更新至最新版。

• Download: https://git-scm.com/

Page 5: VSTS-Git with Visual Studio 入門教學

VSTS – GIT

Page 6: VSTS-Git with Visual Studio 入門教學

TEAM EXPLORER – SELECT GIT PROJECT

Page 7: VSTS-Git with Visual Studio 入門教學

TEAM EXPORER - CLONE

Page 8: VSTS-Git with Visual Studio 入門教學

NEW PROEJCT

Page 9: VSTS-Git with Visual Studio 入門教學

CHANGES

• 第一次,請先確認 Configure 裡的個人資料

Page 10: VSTS-Git with Visual Studio 入門教學

CONFIGURE

• Developer 個人資料

Page 11: VSTS-Git with Visual Studio 入門教學

GITHUB FLOW

• 適合中、小型團隊使用。• https://guides.github.com/introduction/flow/

Page 12: VSTS-Git with Visual Studio 入門教學

STEP 1. CREATE A BRANCH

• master 代表隨時可上戰場的版本• master 僅進行分支與合併• 開發應該在其他 Branch 上進行• 取個好名子

• fix-bugid-9527

• cool-feature-async

• users/kkbruce/test-img-resize ( 建議用” /”)

• 分支命名規範: http://mvc.tw/004M

Page 13: VSTS-Git with Visual Studio 入門教學

STEP 2. COMMIT CHANGES

• Commit 到你的 branch 。• 每次的 commit 都代表往前一小步 ( 一個節點 ) 。• 為了 bug 或 feature ,通常會進行多個

commit 。

Page 14: VSTS-Git with Visual Studio 入門教學

STEP 2.1 IGNORE

• Settings Git Repository Settings

• /.gitIgnore :排除的檔案• /.gitattributes :針對特定路徑的設定值被稱為 Git 屬性 (attributes)

• https://www.gitignore.io/

Page 15: VSTS-Git with Visual Studio 入門教學

唯一的指令

• 已提交至 Repository 的檔案,事後再設定 .gitignore 是沒有用的。• 可透過指令明確跟 Git 說此檔案不需要版本控管了。

• git rm --cached 檔案名稱

Page 16: VSTS-Git with Visual Studio 入門教學

STEP 3. PUSH YOUR BRANCH

• Push 你的 branch 到遠端儲存庫。

Page 17: VSTS-Git with Visual Studio 入門教學

STEP 4. CREATE A PULL REQUEST

• 通知某 ( 些 ) 人進行 Code Review ,以提供更多 feedback 。• 換個說法,分支進行合併前進行最後的討論。• 也許會進行更多的 commit 與 push 。• 由分支負責人進行同意合併動作。

Page 18: VSTS-Git with Visual Studio 入門教學

STEP 5. COMPLETE PULL REQUEST

• 解決任何的衝突,以完成分支合併。

Page 19: VSTS-Git with Visual Studio 入門教學

CHANGES( 變更 )

• 確認 commit 的 Branch 是否正確

Page 20: VSTS-Git with Visual Studio 入門教學

關聯 WORKITEM ( 重要 )

Page 21: VSTS-Git with Visual Studio 入門教學

VSTS 定義查詢

• Query 在 VSTS 去定義• My Queries 僅自己使用的查詢• Sheard Queries 是共享的查詢

Page 22: VSTS-Git with Visual Studio 入門教學

QUERIES SAMPLE

Assigned to All Task

Page 23: VSTS-Git with Visual Studio 入門教學

ACTIONS( 動作 )

Page 24: VSTS-Git with Visual Studio 入門教學

SYNC( 同步 )

• Commit 是簽入至本機儲存庫。• Sync 才會同步至遠端儲存庫。• 可 Commit 多個本機的版本後再執行 Sync 。

Page 25: VSTS-Git with Visual Studio 入門教學

HOME – SYNC( 同步 )

Page 26: VSTS-Git with Visual Studio 入門教學

VSTS – CODE / EXPLORER

Page 27: VSTS-Git with Visual Studio 入門教學

COMMIT 連續技

• Commit

• Commt and Push

• Commit and Sync

Page 28: VSTS-Git with Visual Studio 入門教學

SYNC – PUSH AND PULL

push• 將本機變更推送到遠端

pull• 將遠端變更提取到本機

Page 29: VSTS-Git with Visual Studio 入門教學

BRANCHES

Page 30: VSTS-Git with Visual Studio 入門教學

NEW BRANCH

Page 31: VSTS-Git with Visual Studio 入門教學

PUBLISH BRANCH

Page 32: VSTS-Git with Visual Studio 入門教學

LOCAL BRANCH

• 建立後第一次需要 Publish Branch 至 Server

• 後續就是不斷 commit 與 push 。

Page 33: VSTS-Git with Visual Studio 入門教學

PULL REQUESTS

• Pull Request 字面為「提取要求」,代表子分支請求父分支擁有者給提取回去的要求。• Pull Requests 是一個通用的工作流程,即是對 branch 進行 Code Review 與合併。• 換句話說,目前 branch 已開發、測試至可整合的程度,希望專案擁有者進行審查與合併的動作。

Page 34: VSTS-Git with Visual Studio 入門教學

NEW PULL REQUEST

• Pull 已完成的 commit 至遠端。• 建立 Pull Requests

• 審查與完成審查需連線到 VSTS (online) 完成。

Page 35: VSTS-Git with Visual Studio 入門教學

TITLE & DESCRIPTION

• Title 簡明說明此次 pull request 的更改• Description 簡明說明此更改如何實作以及其他有助理解此更改的資源。• 還可指定 Reviewers 與 Work Items

Page 36: VSTS-Git with Visual Studio 入門教學

DISCUSSION

Page 37: VSTS-Git with Visual Studio 入門教學

FILES

Page 38: VSTS-Git with Visual Studio 入門教學

COMMITS

Page 39: VSTS-Git with Visual Studio 入門教學

COMPLETE PULL REQUEST

• 遠端同意後,記的本機切換回 master 分支( 本範例 ) Sync 一下。

Page 40: VSTS-Git with Visual Studio 入門教學

MASTER - HISTORY

Page 41: VSTS-Git with Visual Studio 入門教學

PULLING

Fetch 下載所做的更改,但不套用在你的程式碼Merge 套用取自 Fetch 到你本地儲存庫的分支Pull 這是一次執行 Fetch 與 Merge 的簡單作法。

Page 42: VSTS-Git with Visual Studio 入門教學

MERGE

• Team Explorer 會在你執行 pull 或 sync 動作時會進行 merge 。• Sync 是 pull 與 push 的組合操作,它是同步本地與遠端的分支的 commit 資料。

Page 43: VSTS-Git with Visual Studio 入門教學

MERGE CONFLICTS

• 同一支檔案被多人異動。• Git 無法解決,則產生合併衝突。

Page 44: VSTS-Git with Visual Studio 入門教學

MERGE CONFLICTS

• 以本機儲存庫為主• 以遠端儲存庫為主

Page 45: VSTS-Git with Visual Studio 入門教學

GIT BRANCHING MODEL

• 2010年時,有位 Vincent Driessen 整理出了一套 Git branching model

Page 46: VSTS-Git with Visual Studio 入門教學

主要 (MASTER) 分支• master :處於 production-ready 的狀態,只從 release 與 hotfix merge 回來,不直接在上面 commit 變更。換句話說,即是該版的 source code 是可運行的、符合專案需求的、設計良好的、穩定的、可維護的、可擴展的及已文件化的。• develop :也稱開發分支為整合分支,自動化測試所根據的程式碼 (source code) 即是以此分支上的版本為基準來進行測試。

Page 47: VSTS-Git with Visual Studio 入門教學

支援分支• Feature branches :從 develop 分支出來,當功能開發修改完成後 merge 回 develop

• Release branches :從 develop 分支出來,是準備釋出的版本,只修改版本號與 bug ,完成後 merge 回 develop 與 master ,並在 master 標上版本號的 tag

• Hotfix branches :從 master 分支出來,主要是處理已釋出版本需要立即修改的錯誤,完成後 merge 回 develop 與 master ,並在 master 標上版本號的 tag

• 支援分支與主要分支最大的差別在於,支援分支在支援任務結束後就會移除,而主要分支則是始終存在。

Page 48: VSTS-Git with Visual Studio 入門教學

功能 (FEATURE) 分支• 從 develop branch 分離。• 合併回 develop branch 。• 分支命名規則:除了 master, develop, release-, or

hotfix- 以外的功能名稱都行。• 此分支通常只會存在於該功能的開發者的本機端的儲存庫 (local repository) ,遠端的中央儲存庫 (remote

repository 或者 remote origin) 是不會有的。

Page 49: VSTS-Git with Visual Studio 入門教學

發佈 (RELEASE)分支

• 從開發分支分離。• 合併回開發分支或主要分支。• 分支命名規則: release-*

Page 50: VSTS-Git with Visual Studio 入門教學

發佈分支

• Release branch 分支是為了新版本發佈而存在• 合適進行整合性測試,並進行小 bug修復及增加一些 metadata( 例如版本號或是 build日期等 ) 。• 制定版本號碼的最佳時機是在開發佈分支時。

Page 51: VSTS-Git with Visual Studio 入門教學

修補 (HOTFIX)分支• 通常是因為出現了一個急需在短時間內修復的 bug(急件 ) ,無法等到下一次發佈時才修復。• 此分支通常從主分支某個已標上 tag 的 commit 分出, bug經過修復後,可合併到開發分支,或者是合併回主分支,並標上另一版本號的 tag 。• 開此分支的目的在於開發分支上的成員可以繼續原本的工作,而 bug修復工作也同時由另外的成員來執行,使得對彼此間的影響降到最低。• 特別注意的是,若修補程式分支與發佈分支同時存在,則當 bug修補已完畢時,就不是合併回開發分支,而是發佈分支。

Page 52: VSTS-Git with Visual Studio 入門教學

GITFLOW FOR VISUAL STUDIO 2015

• http://mvc.tw/004O

Page 53: VSTS-Git with Visual Studio 入門教學

VISUAL STUDIO 2015 UPDATE 2

Page 54: VSTS-Git with Visual Studio 入門教學

結論

• Git 是一套成功的分散式版本控管。• VSTS 提供一個強大的 DevOps 平台, Version Control 與 Git 可以無縫整合。• Team Explorer 去除煩雜的指令,提供簡易介面與操作。• Git + VSTS + Visual Studio 提供高生產力的開發作業流程。• 進一步的 Git 需求,那麼請花點時間瞭解 Git 指令。

Page 55: VSTS-Git with Visual Studio 入門教學

參考資料• https://git-scm.com/book/zh-tw/v1

• https://msdn.microsoft.com/en-us/library/vs/alm/code/git/overview

• https://www.visualstudio.com/en-us/get-started/code/gitquickstart

• https://guides.github.com/introduction/flow/

• http://nvie.com/posts/a-successful-git-branching-model/

• http://git-tutorial.readthedocs.org/zh/latest/branchingmodel.html

• http://www.ruanyifeng.com/blog/2012/07/git.html

• http://huan-lin.blogspot.com/2012/04/git-ignore-file.html

• Book : http://books.gotop.com.tw/v_ACA021200