簡單版的 Github 版控方式,讓新手們能簡單上手,但並不正規。 [toc] ## Git 環境 ### Ubuntu ```bash sudo apt-get install git-all ``` 如何使用:在該資料夾內打開 Terminal,即可輸入指令 ### Windows [Download for Windows](https://git-scm.com/download/win) 如何使用:對該資料夾右鍵,點擊 Git Bash  ### 基本操作 #### 1. 設置好個人資料 ```bash # 設定 git config --global user.name "<yourname>" git config --global user.email "<youremail@gmail.com>" # 查詢 config git config --list ``` <img src="https://github.com/tana0101/NTOU_Arrays_Start_at_One/blob/main/basic/Print%20Screen/git%20config.png?raw=true" alt="Cover" width="60%"/><BR> #### 2. 將 repositories 存入本地 ```bash # https git clone https://github.com/name/Hello-World.git # SSH git clone git@github.com:name/Hello-World.git ``` #### 3. 如何開始操作 對該 Repositorie 資料夾開啟 Git bash 或 Terminal,即可輸入指令。 ## 使用方式 ### 簡單的流程 - 先有 main 與 dev 兩個分支: - main:上線給使用者使用的版本 - dev:新功能上傳到此分支做測試 - 步驟: 創建一個功能的分支 -> 完成此功能 -> 將新功能連同分支合併到 dev -> 合併後就刪除該分支(網站上會問你要不要刪掉) ### 操作示範 1. [從 dev 創建新分支,並在此分支撰寫新功能](https://hackmd.io/glOfHCrjQV-lNngFaDOiOw?view#1-%E6%9C%AC%E5%9C%B0%E5%88%86%E6%94%AF%E6%93%8D%E4%BD%9C) `git switch -c add-login-function` 2. [每完成一個環節就做紀錄與推送](https://hackmd.io/glOfHCrjQV-lNngFaDOiOw?view#2-%E5%A6%82%E4%BD%95%E6%8E%A8%E9%80%81%E8%88%87%E5%8F%96%E5%BE%97) - 加入所有本地修改 `git add .` - 加入本次修改的訊息 `git commit -m "Feat: Add input box."` - 上傳到遠端 Repository `git push git push --set-upstream origin add-login-function` (第一次要設置 upstream) - 之後的每次修改如下 `git add .` `git commit -m "Feat: Add button."` `git push` (已經設置 upstream 就能直接push) 3. [完成功能後,就能丟回原來的分支](https://hackmd.io/glOfHCrjQV-lNngFaDOiOw?view#3-%E5%88%86%E6%94%AF%E5%90%88%E4%BD%B5%E3%80%81%E8%88%87%E5%85%B6%E4%BB%96%E4%BD%BF%E7%94%A8%E8%80%85%E4%BA%92%E5%8B%95%EF%BC%9APull-Request%EF%BC%88PR%EF%BC%89) 到 Github 上的 Repository,去建立 Pull Request  接著寫標題,以及敘述本分支做了哪些事情,也能放圖片。 4. 之後的每個新功能都按照1->2->3的流程進行 <br> - 注意: - 請不要寫無用的 git commit ,應按照 Commit 守則。 - 請敘述清楚 Pull Request(PR)。 - 請善用分支操作,否則團隊難以協同。 - 團隊應該要互相 review code,確保一致性、可讀性。 ## 常用指令 ### 1. 本地分支操作 ```bash # 轉移並新增 branch git switch -c <branch_name> # 轉移到 branch git switch <branch_name> ``` ### 2. 如何推送與取得 ```bash # 加入所有修改內容 git add . # 此次上傳的描述 git commit -m "message" # 上傳到 origin 的 branch_name 分支 git push # 將修改內容下載到本地 git pull ``` #### [應遵守 Commit 守則](https://hackmd.io/@dh46tw/S1NPMsy5L#%E4%B8%80%E3%80%81%E7%82%BA%E4%BB%80%E9%BA%BC%E8%A6%81%E5%AF%ABGit-Commit-Message) 比如:`git commit -m "Feat: Add input box."` |類型 |說明 |程式碼改動| | -------- | -------- | -------- | |Feat |新功能。 |有| |Modify |既有功能需求調整的修改。 |有| |Fix |錯誤修正。 |有| |Docs |更新文件,如 README.md。 |沒有| |Style |程式碼格式調整(formatting)、缺少分號(missing semi colons)等。 |沒有| |Refactor |重構。針對已上線的功能程式碼調整與優化,且不改變記有邏輯。 |有| |Test |測試。新增測試、重構測試等 |沒有| |Chore |更新專案建置設定、更新版本號等瑣事。 |沒有| |Revert |撤銷之前的commit。 revert: type(scope): subject (回覆版本:xxxx) |有| 節錄於 [Git Commit Message 格式與規範整理](https://hackmd.io/@dh46tw/S1NPMsy5L#%E4%B8%80%E3%80%81%E7%82%BA%E4%BB%80%E9%BA%BC%E8%A6%81%E5%AF%ABGit-Commit-Message) ### 3. 分支合併、與其他使用者互動:Pull Request(PR) #### 流程: 建立 PR -> 給大家 review 確認沒問題或是利用留言 -> 自己合併或是讓其他使用者合併 #### 主要功能: 1. 設置 Reviewers:讓其他人收到 review 程式碼的通知,並且給建議。 2. 設置 Development 可以去綁定此 PR 跟那些 Issue 有關係,比如這個 PR 是修復某種 BUG,就可以把該 BUG 的 Issue 連接進來,方便釐清關係。 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up