# Git 筆記 ###### tags: `學習筆記` ## 1. 安裝工具軟體 至 [資料科學組\軟體\Git]() 資料夾下取得以下檔案並依序安裝 1. Git-2.31.1-64-bit.exe 2. ForkInstaller.exe --- ## 2. 設定 Mail & UserName 安裝完成後打開 Git Bash 這邊的 Mail & UserName 會在每次 Commit 時作為紀錄使用 在 Git Bash 中輸入 ```Console $ git config --global user.name "[您的姓名]" $ git config --global user.email "[您的Email]" ``` 輸入完後查詢是否成功 ```Console $ git config --list ``` --- ## 3. 自 Remote 取得 Repository Repository 路徑範例: http://10.216.48.134:8080/tfs/bi/Misc%20Tasks/_git/GitTest 1. Git Bash ```Console $ git clone [Repository路徑] ``` 2. Fork ``` 點選:上方功能表 File > Clone ``` --- ## 4. Branch ### 4.1 切換 Branch 1. Git Bash ```Console $ git checkout [branch名稱] ``` 2. Fork 切換至其他 Local branch ``` 點選:左方功能表 Branches 下欲選擇項目 double click ``` 取得 Remote branch 並 checkout 至 Local 端 ``` 點選:左方功能表 Remotes 下欲選擇項目 double click ``` ### 4.2 Create Branch 1. Git Bash ```Console $ git branch [branch名稱] ``` 2. Fork ``` 點選:左方功能表 Branches 上右鍵 Create New Branch... ``` ### 4.3 Merge Branch branch_A merge into branch_B 1. Git Bash ```Console $ git checkout [branch_A] $ git merge [branch_B] ``` 2. Fork ``` 點選後拖曳:左方功能表 Branches 內點選 branch_A 並拖曳移至 branch_B 上 ``` --- ## 5. 異動後遷入 Git 遷入分為三個階段 1. 確認異動內容 & 暫存異動內容 2. Commit 至本機端當前 Branch 3. Push 至遠端相對應 Branch ### 5.1 確認異動內容 1. Git Bash ```Console $ git status ``` 2. Fork ``` 點選:左方功能表 Changes ``` ### 5.2 暫存異動內容 #### Commit 前要將異動項目加入清單 1. Git Bash ```Console // 單一檔案 $ git add [檔案名稱] // 相同附檔名 $ git add *.[副檔名] // 全部檔案,包含修改&新增&刪除 $ git add . $ git add -A $ git add all ``` 2. Fork ``` 左方功能表 Changes 1. 要 Commit 的項目 Stage 2. 不要的項目 > 右鍵 > Discard Changes... ``` #### Stash,還不打算 Commit 但要切換 Branch 的暫存 1. Git Bash ```Console // 暫存當前異動項目 $ git stash save // 顯示暫存清單 $ git stash list // 復原暫存內容 $ git stash pop // 刪除暫存 $ git stash drop stash@{[stash id]} // 刪除所有暫存 $ git stash clear ``` 2. Fork ``` // 暫存當前異動項目 點選:左上方功能表 Stash // 復原暫存內容 點選:左上方功能表 Stash 的下拉選單,選擇欲復原的 Stash ``` ### 5.3 Commit 至本地端當前 Branch 1. Git Bash ```Console $ git commit -m "[commit message]" ``` 2. Fork ``` 輸入:右下方功能表輸入 Commit subject 點選:右下方 Commit File ``` ### 5.4 Push 至 Remote 在 Push 至遠端前先 Pull (取得當前 Branch 最新版本) 1. Git Bash ```Console $ git pull ``` 2. Fork ``` 點選:左上方功能表 Pull ``` #### 新 Branch Push 至 Remote 1. Git Bash ```Console $ git push ``` 2. Fork ``` 點選:左上方功能表 Push ``` #### Push 至 Remote 相對應 Branch Pull 會自動 Merge 最新版本與本機內容,但有衝突時就需要手動解除衝突後再次 Commit 確認 Merge 沒問題後將修改推送至 remote 1. Git Bash ```Console $ git push -u origin [branch名稱] ``` 2. Fork ``` 點選:左方功能表 Branches 內點選 branch 後右鍵 Push 'branch' to 'origin'... ``` --- ## 6. Tag (標籤) 1. Git Bash ```Console // 列出所有 tag $ git tag // 新增 tag $ git tag [標籤內容] // 新增 tag (包含說明) $ git tag -a [標籤內容] -m "[標籤說明]" // 查看指定 tag $ git show [標籤內容] ``` 2. Fork ``` 點選:右方 Commit 清單中,欲新增 Tag 的 Commit 上右鍵點選 Create Net Tag... ```
×
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