--- tags: NCUGC Author: uccu --- # NCUGC GIT 教學 ### 環境架設 - [安裝git](https://git-scm.com/downloads) - [安裝source tree](https://www.sourcetreeapp.com/) - [github帳號註冊](https://github.com/) ### Why we use git? - 對專案進行版本控制 - 多人協作 ### terminal - 可以使用git功能的地方 #### 常用指令 | 指令 | 說明 | | -------- | -------- | | ls | 顯示當前目錄資料 | | cd [路徑] | 切換目錄 | | mkdir [名稱] | 新增目錄 | | touch [名稱] | 新增檔案 | | rm [檔案] | 刪除檔案 | | clear | 清除畫面 | ### HTML #### 結構 ```htmlmixed= <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="app.css"/> <title>Your title</title> </head> <body> </body> </html> ``` - 給使用者看的東西會在body裡面 #### 標籤 - 大標題:`<h1>我的標題</h1>` - 副標題:`<h2>我的副標題</h2>` ### CSS #### 範例 ```css= h1{ color: purple; background: blue; } ``` ### 基本架構 ![](https://i.imgur.com/U700LyG.jpg) - 工作目錄:你目前處理檔案的目錄 - 索引:對數據庫提交作準備的暫存區 - 本地數據庫:記錄檔案和目錄狀態的地方 - 本地:在個人電腦上 - 遠端:在遠端伺服器上 ### 檔案生命週期 ![](https://git-scm.com/figures/18333fig0201-tn.png) ### git基本指令 #### 第一次使用,輸入 - 名稱:`git config --global user.name "[名稱]"` - E-mail:`git config --global user.email "[e-mail]"` #### 基礎操作 - 建立新數據庫:`git init` - 檢查檔案狀態:`git status` - 將檔案加入索引:`git add .` - 檢視索引檔案成為一個更新:`git commit -m "[訊息]"` - 檢視繳交的歷史紀錄:`git log` - 查看版本內容 `git checkout [編號]` #### 遠端數據庫 - 加入遠端數據庫:`git remote add origin [數據庫網址]` - 下載遠端數據庫:`git clone [數據庫網址]` - 更新遠端數據庫:`git push origin master` - 下載遠端數據庫資料:`git fetch` - 合併遠端數據庫資料:`git pull origin master` #### 分支 - [分支教學](https://gitbook.tw/chapters/branch/using-branch.html) - 查看所有分支:`git branch` - 建立分支:`git branch [分支名稱]` - 刪除分支:`git branch -d [分支名稱]` - 查看版本內容:`git checkout [分支名稱]` - 合併分支:`git merge [分支名稱]` - 不使用fast forward:`git merge [分支名稱] --no-ff` - 如果跳出神奇的東西:`esc -> 打:wq -> enter` #### 還原 - [reset教學](https://gitbook.tw/chapters/using-git/reset-commit.html) - 還原一個版本:`git reset HEAD^` - 放棄所有更新檔案:`git reset HEAD^ --hard` | 模式 | mixed | soft | hard | | -------- | -------- | -------- | -------- | | 工作目錄 | 不變 | 不變 | 丟掉 | | 索引 | 丟掉 | 不變 | 丟掉 | - 檢視詳細歷史紀錄:`git reflog` - 還原到特定commit:`git reset [commit編號] --hard` ### 進階指令 #### tag - 為某個commit做標記 - [使用標籤](https://gitbook.tw/chapters/tag/using-tag.html) - 建立標籤:`git tag v1.0` #### cherry-pick - 撿特定commit做合併 - [如果你只想要某個分支的某幾個 Commit?](https://gitbook.tw/chapters/faq/cherry-pick.html) - 建立標籤:`git cherry-pick [編號]` #### stash - 儲存當前目錄與索引狀態 - [手邊的工作做到一半,臨時要切換到別的任務](https://gitbook.tw/chapters/faq/stash.html) - 新增stash:`git stash -u` - 查看stash:`git stash list` - 拿回stash:`git stash apply [stash名稱]` #### revert - 做出一個「取消」的 Commit - [Reset、Revert 跟 Rebase 指令有什麼差別?](https://gitbook.tw/chapters/rewrite-history/reset-revert-and-rebase.html) - 新增revert:`git revert HEAD --no-edit` #### rebase - 重新定義某個分支的參考標準(base) - [另一種合併方式](https://gitbook.tw/chapters/branch/merge-with-rebase.html) - 使用變基:`git rebase 分支名稱` ### Github Flow - [唐鳳改錯字](https://www.setn.com/News.aspx?NewsID=704152) - [Understanding the GitHub flow](https://guides.github.com/introduction/flow/) ### 如何在unity使用git - 在你的專案資料夾init一個數據庫 - 如果這時直接add會有問題 #### unity設定 - Edit - Project Setting - Editor - Version Control - 選擇 Visible Meta Files - Asset Serialization - 選擇 Force Text #### 在工作目錄增添.gitignore [有些檔案我不想放在 Git 裡面…](https://gitbook.tw/chapters/using-git/ignore.html) [unity的gitignore設定檔](https://github.com/github/gitignore/blob/master/Unity.gitignore) #### 設定.gitattributes [unity的gitattributes設定檔](https://gist.github.com/nemotoo/b8a1c3a0f1225bb9231979f389fd4f3f) #### merge tool [Smart Merge](https://docs.unity3d.com/Manual/SmartMerge.html?_ga=2.22946299.1384245422.1590404283-661507878.1589203725) ## 學習資源 [六角學院-git、github教學](https://www.youtube.com/playlist?list=PLYrA-SsMvTPOZeB6DHvB0ewl3miMf-2tj) [git learning 遊戲](https://learngitbranching.js.org) [為你自己學 Git](https://gitbook.tw/) [連猴子都能懂的Git入門指南](https://backlog.com/git-tutorial/tw/)