2022年4月15日 星期五

Git 指令

乾合併


--no-ff 不要快速合併
--no-commit 不要直接發 commit ,先進暫存
git merge master --no-commit --no-ff
(將 master Merge 到當前的 branch)
git merge main --no-commit --no-ff
(將 main Merge 到當前的 branch)


Local


當 Remote Branch 被刪除時,僅用來刪除 Local 殘留的 origin branch
git branch -r -d origin/1-branch


Remote


檢視 Remote 路徑
git remote -v
更新 Remote 路徑
git remote set-url origin {URL}
(would clobber existing tag) 更新 Local Tag 問題
git fetch --tags -f
將尚未發布任何 commit 的遠端 1-branch 分支強制移動到 main 分支
git push origin main:1-branch --force


Worktree


建立 Branch 並另開工作目錄
git worktree add -b worktree_branch ../worktree_folder master
檢視目前的 Worktree 清單
git worktree list
刪除 Worktree ,直接刪除目錄,然後執行
git worktree prune


Reset


遠端有 commit 但是後來 Rebase 成一個時,要將本地強制更新成遠端的版本
先確保有抓到遠端最新的狀態
git fetch origin
強制把目前的進度切換成跟遠端完全一樣的版本
git reset --hard origin/1-issue

Git Graph 設定 UI Rebase


Antigravity

Cmd + Shift + P 叫出命令選擇區搜尋
Shell Command: Install 'agy' command in PATH
終端機輸入指令
git config --global core.editor "agy --wait"
git config --global sequence.editor "agy --wait"
VSCode

Cmd + Shift + P 叫出命令選擇區搜尋
Shell Command: Install 'code' command in PATH
終端機輸入指令
git config --global core.editor "code --wait"
git config --global sequence.editor "code --wait"

1. 尋找基準點:在 Git Graph 線圖上,找到要合併的所有 commit 的「前一個」節點按右鍵,點選 Rebase current branch on this Commit... 選項。
2. 開啟互動模式:在跳出來的確認視窗中,把 Launch Interactive Rebase 打勾,按下確認按鈕。
3. 設定合併動作:在彈出的圖形化介面裡,把最下面也就是最舊的那個 commit 動作維持在 Pick,然後把上面其他比較新的 commit 動作選單都改成 Squash,接著按下 Start Rebase。
4. 整理歷史訊息:在接著出現的文字編輯分頁中,把擠在一起的 commit 訊息刪減整理,留下最清楚的一段描述(記得避開井字號在第一行開頭的小陷阱,可以在 # 前面放個空格),整理好後存檔並關閉分頁。
5. 安全推送到遠端:回到 Git Graph 線圖,對著現在的本地分支標籤按右鍵,選擇 Push Branch...,在跳出的視窗中務必勾選 Force (With Lease) 選項,最後送出就可以完美覆蓋遠端紀錄。

沒有留言:

張貼留言