# Git Intro ###### tags: `FET` `GIT` ![](https://i.imgur.com/DpbiQUH.png) > 1. Git基本介紹 > 2. 開發流程DEMO ---- ## 前言 - 開發過程不外乎寫**程式 > 測試 > 存檔 > 上傳部屬**。 - 透過Git的功能可以做到多人協同與版本控制。讀完本篇可以對Git 有基礎的認識。 - DEMO在DataBricks上使用Azure Repo。 ---- ## 1. Git基本介紹 ---- ![](https://i.imgur.com/TUzgg9n.png) ---- ### Git 多人協同 + 版本控制 git是一個分散式版本控制軟體,最初由林納斯·托瓦茲創作,於2005年以GPL授權條款釋出。最初目的是為了更好地管理Linux核心開發而設計 ---- ![](https://i.imgur.com/qBYKZJR.png) ---- ### Add ``` git add foo.py git add . ``` - 將檔案加入追蹤 - 追蹤之後的任何異動都會留下紀錄,極難消除軌跡 - 不想追蹤的檔案可以放在 .gitignore ,例如log檔、環境設定檔 - 保持乾淨,只留主程式碼 - 放小檔,excel不支援code diff - 所有的檔案都放在.git資料夾下,只要刪掉.git 就可以一切重來 ---- ### Commit ``` git commit -m "first commit" ``` - 針對當次的開發進度做提交 - 不能留空 - 類比為使用word時的存檔動作,或是玩遊戲時的存檔 - 可以回朔到過去的任一次commit ---- ### Branch ``` git branch develop git branch sprint1/DavidWang git checkout sprint1/DavidWang ``` - 開發進度的分身、遊戲存檔的copy - 成本很低,可以依需求開多個分支 - 最簡單的用法切分為 master/develop ---- ### Remote/ Push / Pull ``` git push git pull ``` - Remote: 統一管理Repo的地方,例如 GitHub/ GitLab/ Azure Repo/ BitBucket - push:將開發進度推(更新)到Remote - pull: 將開發進度從Remote拉(更新)到local - commit & push 通常是一起做的,也可以累積多個commit 一次push ---- ### Merge ``` git checkout master git merge develop ``` - Merge: 將開發進度合併到主支線 (develop merge into master) - 開發同一支程式時需要解conflict ---- ### PR (Pull Request) - 通常會設立Reviewer - 程式確定可以正常執行再做PR - 合併到master後,通常會設定CICD自動上版prod - 使用UI操作 ---- ### 優點 - 整合CICD 威力強大 - Code Diff - 省掉稽核文書工作的第一步 ---- ### GitFLow ![](https://i.imgur.com/xOA2qfr.png) ---- ### Git Commit Message 撰寫慣例 ``` feat: 新增/修改功能 (feature)。 fix: 修補 bug (bug fix)。 docs: 文件 (documentation)。 style: 格式 (不影響程式碼運行的變動 white-space, formatting, missing semi colons, etc)。 refactor: 重構 (既不是新增功能,也不是修補 bug 的程式碼變動)。 perf: 改善效能 (A code change that improves performance)。 test: 增加測試 (when adding missing tests)。 chore: 建構程序或輔助工具的變動 (maintain)。 revert: 撤銷回覆先前的 commit 例如:revert: type(scope): subject (回覆版本:xxxx)。 ``` ---- ### Commit 範本1 ``` [sprint1][dev] [sprint1][fix] [sprint1][hotfix] [sprint1][md] ``` ---- ### Commit 範本2 ``` [sprint1][dev] issue #456 ``` ---- ### 版本號 tag(Optional) - GNU 風格 [主版本號].[次版本號].[修訂版本號] ``` 1.0.001 ``` --- ## 2. 開發流程操作 ### 動手玩 https://gitbook.tw/playground#freeplay ---- ### DEMO Git with DataBricks and Azure Repo
{"metaMigratedAt":"2023-06-17T18:40:13.659Z","metaMigratedFrom":"YAML","title":"Git Intro","breaks":true,"disqus":"hackmd","slideOptions":"{\"theme\":\"simple\",\"transition\":\"fade\",\"spotlight\":{\"enabled\":true}}","contributors":"[{\"id\":\"27e5f37e-eca5-4de1-8bad-e3fb269a144a\",\"add\":3274,\"del\":837}]"}
    265 views