Tutorial_Git-UploadOldProject/README.md
2023-10-24 15:51:47 +08:00

185 lines
4.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Old Project
此專案示範如何將手邊上傳至 Gitea
## 環境準備
### Git
如 SVN為操作指令必要安裝至[Git 官網](https://git-scm.com/)下載安裝即可。
![Git](doc_image/2023-10-20-16-28-09.png)
### SourceTree
如 TortioseSVN為 Git 操作 IDE 版本控管 Tools至[SourceTree 官網](https://www.sourcetreeapp.com/)下載安裝即可。
![SourceTree](doc_image/2023-10-20-14-11-15.png)
## Gitea 新增 Repository(儲存庫)
主機位置:[http://twvoadtpw100004/](http://twvoadtpw100004/)
1. 首頁進入組織
於 Gitea 登入後首頁儀表板點選`組織`頁籤,點選 `OAD-WebTeam` 進入組織頁面。
![首頁儀錶板](doc_image/2023-10-20-10-23-38.png)
2. 新增儲存庫
進入組織頁面後,點擊`新增儲存庫`按鈕新增 git 專案。
![組織頁面](doc_image/2023-10-20-10-28-19.png)
3. 登打儲存庫資料
填寫儲存庫名稱(專案名稱),擁有者須為 `OAD-WebTeam` ,瀏覽權限設定為 `Private 私有`,相關資料填妥後建立儲存庫。
![新增儲存庫](doc_image/2023-10-20-10-31-38.png)
4. 完成建立儲存庫
![儲存庫](doc_image/2023-10-20-13-57-46.png)
## 專案 git 初始化
### 建置 .gitignore 範本
為避免 git 同步時,上傳不必要檔案(ex. packages、node_modules),故會於該檔案設定忽略同步目錄。
1. 至[gitignore](https://www.toptal.com/developers/gitignore)找到對應開發 IDE/技術範本文件
![gitignore](doc_image/2023-10-20-16-22-39.png)
2. 下載儲存至專案根目錄 `.gitignore` (內容以 Visual Studio 為例)
![content](doc_image/2023-10-20-16-23-21.png)
### 上傳 Source Code
專案將依照 [GitFlow](https://gitbook.tw/chapters/gitflow/why-need-git-flow) 原則進行版控,操作方式以 [使用 command line git 指令操作](#使用-command-line-git-指令操作) 或 [使用 SourceTree 介面操作](#使用-sourcetree-介面操作) 兩種方式擇一即可。
#### 使用 command line git 指令操作
1. 打開 cmd 視窗並移動至專案目錄
```cmd
cd /d D:\_SRC\_Coder\Git\OldProject\
```
2. git 初始化
```cmd
git init
```
![git init](doc_image/2023-10-24-14-21-34.png)
執行完成後會產生 `.git` folder
![.git folder](doc_image/2023-10-24-14-08-33.png)
3. 設定 Remote
設定遠端 Git 主機位置
```cmd
git remote add origin http://twvoadtpw100004/OAD-WebTeam/OldProject.git
```
4. Commit & Push
本階段我們將第一次同步並推送至主機
- git add增加異動清單(暫存)
```cmd
git add -A
```
![git add](doc_image/2023-10-20-16-45-46.png)
- git commit登打異動資訊
```cmd
git commit -m "Initial commit"
```
![git commit](doc_image/2023-10-24-15-40-27.png)
- `git flow` 機制建立
```cmd
git flow init -d
```
![git flow init](doc_image/2023-10-24-14-25-58.png)
- 上傳至遠端主機
```cmd
git push -u origin master
git push -u origin develop
```
![git push master](doc_image/2023-10-24-15-46-56.png)
![git push develop](doc_image/2023-10-24-15-47-33.png)
#### 使用 SourceTree 介面操作
1. 開啟 `SourceTree` ,至 `Create` 頁籤,填入程式相關路徑及專案名稱後,新增即可。
![Create](doc_image/2023-10-20-11-30-23.png)
若有跳出提示表示資料夾已存在,點擊 Yes 繼續即可。
![CreateAlert](doc_image/2023-10-24-14-33-01.png)
執行完成後會產生 `.git` folder
![.git folder](doc_image/2023-10-24-14-08-33.png)
2. 新增 Remote
![Remote](doc_image/2023-10-20-11-35-47.png)
![configuration](doc_image/2023-10-20-11-36-40.png)
3. 設定 Remote 資訊Remote name 勾選 `Default remote` ,登打 Gitea Repository 路徑及登入帳號。
![Remote](doc_image/2023-10-24-14-38-12.png)
![Remote info](doc_image/2023-10-24-14-37-17.png)
4. 設定 statged files
![add](doc_image/2023-10-24-14-58-05.png)
![add done](doc_image/2023-10-24-14-59-21.png)
5. 登打 commit message
在文字框內登打 `Initial commit` 後,點擊 `commit` 按鈕。
![Initial commit](doc_image/2023-10-24-15-14-33.png)
6. 切換至左方 `BRANCHS` 底下 `master` 分支,我們會看到剛剛增加的 commit並點擊該項目可於下方查看異動項目清單。這時我們點擊右上角 `Git-flow` 按鈕設定未來上版規則。
![Setting Git-flow](doc_image/2023-10-24-15-27-43.png)
7. 使用預設即可,按 OK。
![OK](doc_image/2023-10-24-15-21-37.png)
8. 完成建立 Git-flow 規則
![Git-flow](doc_image/2023-10-24-15-30-33.png)
### 注意事項
- 如果執行 `git push` 有跳出輸入帳號密碼資訊,輸入 Gitea 帳密即可。
![輸入帳密](doc_image/2023-10-20-16-40-29.png)