# Git簡介 ### 主講人:黃夙賢 ![](https://i.imgur.com/tDdWJe6.png) --- ## 程式開發的共同問題 - 檔案版本之間的差異 - 無法得知備份的原因 - 無法追蹤修改的內容 - 多人共同開發,以上問題會更加凸顯 ## <font color=red>因此需要版本控制系統</font> --- ## Git - 免費、開源之<font color=red>**分散式**</font>版本控制系統 - 由Linus Torvalds (Linux開發者)為了管理程式版本,於2005年開發釋出 - Github是Git的雲端版本控制系統 ![](https://i.imgur.com/pGTlkiK.png) --- ## 版本控制 - 更動前 v.s. 更動後的程式碼 - 修改者 - 修改時間 - 修改原因(修改者需要撰寫 commit message) ![](https://i.imgur.com/EzL6owJ.png =500x) #### 參考來源:[alphacamp](https://tw.alphacamp.co/blog/git-github-version-control-guide) --- ## 版本切換 - 當程式出錯時,有辦法在不同版本中切換 ![](https://i.imgur.com/AgkU0Hj.png) --- ## 分支功能 - 利用分支(branch),開發不同功能之程式 ![](https://i.imgur.com/T5ZGVaY.png) --- ## Git安裝 - https://git-scm.com - 點選"Download for Windows"即可安裝 ![](https://i.imgur.com/iBdNoQA.png =600x) --- ## Git步驟 1. git init  在 Workspace 創建 .git 目錄 2. git add  建立索引 3. git commit 至本地資料庫 (Local Repository) 4. git config 設定環境 (第一次使用才需設定) 5. git push 至 GitHub 資料庫 (Remote Repository) ![](https://i.imgur.com/fQ25Ukz.png =450x) --- ## Git 範例 1. 開啟git bash 2. mkdir git_test 3. cd git_test 4. touch a.txt 5. git init 6. git add a.txt 7. git config --global user.name "xxx" 8. git config --global user.email "xxx@xxx" 9. git commit -m "a.txt" 10. git status --- ![](https://i.imgur.com/wJDCfXA.png) --- ## Git如何上傳到Github 1. 先在Github註冊帳號 2. 在Github新增一儲存庫(Repository),取名為git ![](https://hackmd.io/_uploads/SJ72auErn.png =700x) ![](https://hackmd.io/_uploads/Syf0puEB2.png =700x) --- 3. git branch -M main 4. git remote add origin https://github.com/**帳號**/git.git 5. git push -u origin main 6. 輸入github帳號密碼 ![](https://hackmd.io/_uploads/SkTkJtNS2.png) --- ## Git LFS大型檔案上傳 - 大於10MB的檔案 - git lfs install - git lfs track "檔案" - git add "檔案" - git commit -m "註解" - git remote add origin https://github.com/shhuangmust/bigdata.git - git push -u origin main ---
{"metaMigratedAt":"2023-06-17T00:20:42.750Z","metaMigratedFrom":"YAML","title":"Git簡介","breaks":true,"contributors":"[{\"id\":\"ef0225b9-6c2a-4012-82c9-fa1031d2c4db\",\"add\":2346,\"del\":395}]"}
    300 views