From 62834b591895bb735288042ea9d6d0352b792a2b Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sun, 30 Nov 2025 08:40:29 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 14 ++ README.md | 3 + commands/commit-push-all.md | 154 +++++++++++++++++++ commands/commit-push.md | 174 ++++++++++++++++++++++ commands/resolve-conflict.md | 44 ++++++ plugin.lock.json | 57 +++++++ skills/resolving-conflict/SKILL.md | 229 +++++++++++++++++++++++++++++ 7 files changed, 675 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 commands/commit-push-all.md create mode 100644 commands/commit-push.md create mode 100644 commands/resolve-conflict.md create mode 100644 plugin.lock.json create mode 100644 skills/resolving-conflict/SKILL.md diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..3060701 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,14 @@ +{ + "name": "git", + "description": "Git tools", + "version": "1.0.1", + "author": { + "name": "Miles Chou" + }, + "skills": [ + "./skills" + ], + "commands": [ + "./commands" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..952797e --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# git + +Git tools diff --git a/commands/commit-push-all.md b/commands/commit-push-all.md new file mode 100644 index 0000000..80e7748 --- /dev/null +++ b/commands/commit-push-all.md @@ -0,0 +1,154 @@ +--- +description: Commit and Push All +allowed-tools: Bash(git add:*),Bash(git branch:*),Bash(git diff:*),Bash(git log:*),Bash(git push:*),Bash(git status:*),Bash(git symbolic-ref:*) +model: claude-haiku-4-5 +--- + +無條件將所有變更提交並推送到遠端儲存庫,不考慮提交原子性。 + +## 工作目錄資訊 + +將所有檔案加入暫存區: + +``` +# 執行 git add . +!`git add .` +``` + +檔案變更與暫存狀態的清單: + +``` +!`git status --short` +``` + +檔案變更的詳細內容: + +``` +!`git diff --cached` +``` + +最近五筆提交訊息: + +``` +!`git log --oneline -5` +``` + +分支資訊: + +- **遠端主要分支**: !`git symbolic-ref refs/remotes/origin/HEAD` +- **當前分支**: !`git branch --show-current` + +所有分支清單: + +``` +# 本地分支 +!`git branch` + +# 遠端分支 +!`git branch -r` +``` + +## 流程 + +### 步驟 1:確認目標分支 + +分析「工作目錄資訊」中收集到的變更狀態,總結所有變更內容。 + +使用 AskUserQuestion 工具詢問目標推送分支: + +**問題**:要推送到哪個分支? +- 選項:`[當前分支: main]` / `[branch1]` / `[branch2]` + +分支選項建議: +- **當前分支** - 在目前的分支上提交並推送 +- **其他可能的分支** - 根據修改內容推測相關的分支名稱 + +若使用者手動輸入的分支名稱不存在,則建立新分支。 + +**注意事項**: +- 除非必要,否則不要提供「切換到新的分支」的選項 +- **IMPORTANT**:若使用者沒有回答或回答空白選項,則必須重新確認 + +### 步驟 2:產生提交訊息 + +根據記憶中的提交訊息格式偏好產生提交訊息,若無特別指示則使用以下格式: + +#### 基本格式 + +``` +<簡短描述所有變更> + +- : <變更描述> +- : <變更描述> +- : <變更描述> +``` + +- **標題**:簡單描述這次提交的整體內容(不使用 Conventional Commits 前綴) +- **內容**:使用 Conventional Commits 類型標示各項變更 + +#### Conventional Commits 類型 + +- `feat`: 新功能 +- `fix`: 修復問題 +- `docs`: 文件更新 +- `style`: 程式碼格式調整 +- `refactor`: 重構 +- `test`: 測試 +- `chore`: 建置或輔助工具 + +#### 範例 + +**範例 1:混合類型變更** +``` +更新認證系統與文件 + +- feat: 新增 OAuth 登入功能 +- fix: 修正驗證碼過期問題 +- docs: 更新 API 文件 +- test: 補充單元測試 +``` + +**範例 2:單一類型多項變更** +``` +完善登入驗證功能 + +- feat: 實作 email 驗證邏輯 +- feat: 加入驗證碼過期檢查 +- test: 更新相關單元測試 +``` + +**範例 3:簡單變更** +``` +修正登入頁面錯誤訊息顯示 + +- fix: 修正驗證失敗時的錯誤訊息 +``` + +### 步驟 3:執行提交與推送 + +#### 3-1. 提交 + +所有檔案已在「工作目錄資訊」階段加入暫存區,使用步驟 2 產生的提交訊息執行 commit: + +```bash +git commit -m <提交訊息> +``` + +#### 3-2. 推送 + +推送到使用者選擇的分支: + +```bash +git push -u origin <分支名稱> +``` + +## 注意事項 + +### 提交特性 +- **全部提交**:此指令會無條件提交工作目錄中的所有變更 +- **不考慮原子性**:即使包含多種類型的修改,也會合併成單一提交 +- 提交訊息應盡可能清楚描述所有變更內容 + +### 錯誤處理 +- 執行指令偶爾會出現 `.git/index.lock` 鎖定的錯誤,當指令提示詞正常啟動後,可以忽略這個錯誤 +- 遇到其他任何錯誤時立即停止,回報錯誤訊息給使用者 diff --git a/commands/commit-push.md b/commands/commit-push.md new file mode 100644 index 0000000..9e254aa --- /dev/null +++ b/commands/commit-push.md @@ -0,0 +1,174 @@ +--- +description: Commit and Push +allowed-tools: Bash(git add:*),Bash(git branch:*),Bash(git diff:*),Bash(git log:*),Bash(git reset:*),Bash(git push:*),Bash(git status:*),Bash(git symbolic-ref:*) +model: claude-haiku-4-5 +--- + +協助產生符合專案規範的提交訊息,並推送到遠端儲存庫。 + +## 工作目錄資訊 + +將所有檔案重新設定成追蹤清單: + +``` +!`git add -N .` +``` + +檔案變更與暫存狀態的清單: + +``` +!`git status --short` +``` + +檔案變更的詳細內容: + +``` +!`git diff` +``` + +最近五筆提交訊息: + +``` +!`git log --oneline -5` +``` + +分支資訊: + +- **遠端主要分支**: !`git symbolic-ref refs/remotes/origin/HEAD` +- **當前分支**: !`git branch --show-current` + +所有分支清單: + +``` +# 本地分支 +!`git branch` + +# 遠端分支 +!`git branch -r` +``` + +## 流程 + +### 步驟 1:分析工作目錄資訊 + +分析「工作目錄資訊」中收集到的變更狀態,使用一次 AskUserQuestion 工具同時確認: +1. 要提交的檔案範圍(是否符合提交原子性) +2. 目標推送分支 + +#### 1-1. 檔案變更狀態 + +分析工作目錄的變更,判斷是否符合提交原子性: + +**符合原子性**:所有變更都屬於同一個邏輯修改 +- 不使用 AskUserQuestion 詢問檔案範圍 +- 只詢問目標推送分支 +- 直接提交所有變更 + +**違反原子性**:包含多個不相關的修改 +- 依 Conventional Commits 類型分類檔案: + - `feat:` 新功能 + - `fix:` 修復問題 + - `docs:` 文件更新 + - `style:` 程式碼格式調整 + - `refactor:` 重構 + - `test:` 測試 + - `chore:` 建置或輔助工具 + +- 輸出分類後的預計 commit message 和前三個重要檔案: + ``` + 1. feat: [commit message] + - [檔案路徑] + - [檔案路徑] + - [檔案路徑] + 2. docs: [commit message] + - [檔案路徑] + ``` + +- 在 AskUserQuestion 中提供複選選項,讓使用者選擇要提交哪些分類 + +#### 1-2. 分支狀態 + +在 AskUserQuestion 中提供分支選項: +- **當前分支** - 在目前的分支上提交並推送 +- **其他可能的分支** - 根據修改內容推測相關的分支名稱 + +若使用者手動輸入的分支名稱不存在,則建立新分支。 + +**注意:除非必要,否則不要提供「切換到新的分支」的選項** + +#### 1-3. AskUserQuestion 範例 + +同時詢問檔案範圍和目標分支,例如: + +**問題 1**:要提交哪些變更? +- 選項:`[feat: 新增登入功能]` / `[docs: 更新 README]` + +**問題 2**:要推送到哪個分支? +- 選項:`[當前分支: main]` / `[branch1]` / `[branch2]` + +**IMPORTANT**:在使用 AskUserQuestion 工具時,若使用者沒有回答或回答空白選項,則必須重新確認 + +### 步驟 2:產生提交訊息 + +根據記憶中的提交訊息格式偏好產生提交訊息,若無特別指示則使用 **Conventional Commits** 規範: + +#### 基本格式 + +``` +(): + + +``` + +- `type`: 提交類型(feat, fix, docs, style, refactor, test, chore) +- `scope`: 影響範圍(選填) +- `subject`: 簡短描述(50 字以內) +- `body`: 詳細說明(選填,使用 bullet points) + +範例 + +``` +feat(auth): 新增登入驗證功能 + +- 實作 email 驗證邏輯 +- 加入驗證碼過期檢查 +- 更新相關單元測試 +``` + +### 步驟 3:執行提交與推送 + +#### 3-1. 加入檔案 + +先重置暫存區: + +```bash +git reset . +``` + +然後根據步驟 1 使用者選擇的檔案範圍,使用 `git add` 加入檔案。 + +#### 3-2. 提交 + +使用步驟 2 產生的提交訊息執行 commit: + +```bash +git commit -m <提交訊息> +``` + +#### 3-3. 推送 + +推送到使用者選擇的分支: + +```bash +git push -u origin <分支名稱> +``` + +## 注意事項 + +### 提交原則 +- 每個提交應保持原子性,只包含相關的變更 +- 提交訊息應清楚描述變更內容和原因 + +### 錯誤處理 +- 執行指令偶爾會出現 `.git/index.lock` 鎖定的錯誤,當指令提示詞正常啟動後,可以忽略這個錯誤 +- 遇到其他任何錯誤時立即停止,回報錯誤訊息給使用者 diff --git a/commands/resolve-conflict.md b/commands/resolve-conflict.md new file mode 100644 index 0000000..80da983 --- /dev/null +++ b/commands/resolve-conflict.md @@ -0,0 +1,44 @@ +--- +description: 解決 Git 衝突 +allowed-tools: Bash(git status:*),Bash(git diff:*),Bash(git log:*),Skill(git:resolving-conflict) +model: claude-sonnet-4-5 +--- + +協助解決當前的 Git Rebase 或 Merge 衝突。 + +## 工作流程 + +### 1. 檢查衝突狀態 + +先檢查當前是否處於衝突狀態: + +``` +!`git status` +``` + +### 2. 判斷處理方式 + +根據 git status 的結果: + +**有衝突:** +- 如果偵測到衝突(rebase in progress 或 You have unmerged paths),使用 Skill tool 調用 `git:resolving-conflict` +- 該 skill 會系統化地引導解決所有衝突 + +**無衝突:** +- 提示使用者目前沒有衝突需要解決 +- 說明此指令適用於 `git rebase` 或 `git merge` 過程中遇到衝突的情況 + +## 使用場景 + +此指令適用於以下情況: + +- 執行 `git rebase` 時遇到衝突 +- 執行 `git merge` 時遇到衝突 +- 需要系統化地處理多個衝突檔案 +- 不確定如何正確解決衝突時 + +## 注意事項 + +- 解決衝突前會先展示完整的衝突內容 +- 使用 AskUserQuestion 提供所有可能的解決方案 +- 解決後建議執行測試確保功能正常 diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..353ca18 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,57 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:MilesChou/claude-marketplace:plugins/git", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "7acdcac8426c3b02201fc00a2cbf82640ae651a2", + "treeHash": "babf482fdaef16c294a2e9617197b2dc980759690cc61757a971b7bb232d9046", + "generatedAt": "2025-11-28T10:12:07.564580Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "git", + "description": "Git tools", + "version": "1.0.1" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "cec10156b5ac1311ff635ad1ec73ad87c2d769477133039cf608ffb4dabc038b" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "fa45c245f66627315f4fd7f497fe6e1a9a1f37fd7e2781d4538549602f4a0f78" + }, + { + "path": "commands/commit-push-all.md", + "sha256": "7ef85651f898e94cb0bfd35002e34ada887c7b05f7bd782a6c77920a11c15005" + }, + { + "path": "commands/resolve-conflict.md", + "sha256": "9cee29fe1f3717a4c5041caeaba0ad3225e7d7ae2e9de66dd8c9ddb7d6548cba" + }, + { + "path": "commands/commit-push.md", + "sha256": "020c46e82a99db69e32ecb2ea3f5b19b4be762964d3f72941b1c75f509c9fca4" + }, + { + "path": "skills/resolving-conflict/SKILL.md", + "sha256": "fae6c996570a0a912d6e1f66ed5a626e4c1042ba1ef94b91050c14683a91a747" + } + ], + "dirSha256": "babf482fdaef16c294a2e9617197b2dc980759690cc61757a971b7bb232d9046" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file diff --git a/skills/resolving-conflict/SKILL.md b/skills/resolving-conflict/SKILL.md new file mode 100644 index 0000000..dfa9a28 --- /dev/null +++ b/skills/resolving-conflict/SKILL.md @@ -0,0 +1,229 @@ +--- +name: Resolving-Conflict +description: 協助解決 Git Rebase 或 Merge 過程中的衝突,提供系統化的衝突解決流程。 +--- + +# 解決 Git 衝突 + +協助使用者系統化地解決 Git Rebase 或 Merge 過程中的衝突。 + +## 核心功能 + +- 偵測當前的衝突狀態(rebase 或 merge) +- 列出所有衝突的檔案 +- 逐個檢視並解決衝突 +- 完成 rebase 或 merge 流程 + +## 執行步驟 + +### 1. 偵測衝突狀態 + +檢查當前是否處於衝突狀態: +```bash +git status +``` + +確認是 rebase 還是 merge 衝突: +- Rebase: 會顯示 `rebase in progress` +- Merge: 會顯示 `You have unmerged paths` + +### 2. 列出衝突檔案 + +使用以下指令列出所有衝突的檔案: +```bash +git diff --name-only --diff-filter=U +``` + +或從 git status 中擷取: +```bash +git status --short | grep "^UU\|^AA\|^DD\|^AU\|^UA\|^UD\|^DU" +``` + +### 3. 解決衝突 + +對於每個衝突的檔案: + +1. **讀取檔案內容** + - 使用 Read tool 檢視衝突標記 + - 識別衝突區塊(`<<<<<<<`, `=======`, `>>>>>>>`) + +2. **展示衝突資訊** + - **IMPORTANT**: 在詢問使用者前,必須先清楚展示衝突的詳細內容 + - 明確標示雙方的修改內容 + - 說明衝突發生的位置和原因 + - 範例格式: + ``` + 檔案:src/example.ts + 衝突位置:第 10 行 + + 衝突內容比對: + <<<<<<< HEAD (當前分支) + const value = "version A" + ======= + const value = "version B" + >>>>>>> 合併進來的分支 + ``` + +3. **使用 AskUserQuestion 提供解決選項** + - 列出所有可能的解決方案 + - 對於簡單衝突,提供: + - 保留當前分支版本(ours) + - 採用合併進來的版本(theirs) + - 對於需要手動整合的情況,明確列出所有組合: + - 方案 A + 方案 B + - 方案 B + 方案 A + - 其他自訂組合 + - 讓使用者基於完整資訊做出選擇 + +4. **執行解決** + - 使用 Edit tool 根據使用者選擇移除衝突標記 + - 保留或整合正確的程式碼 + +5. **標記為已解決** + ```bash + git add <檔案路徑> + ``` + +### 4. 完成流程 + +所有衝突解決後: + +**Rebase:** +```bash +git rebase --continue +``` + +如果遇到「You must edit all merge conflicts」錯誤,可能是索引狀態不一致,使用以下方式重置: +```bash +git reset && git add <已解決的檔案> && git rebase --continue +``` + +**Merge:** +```bash +git commit +``` + +如果需要放棄: +- Rebase: `git rebase --abort` +- Merge: `git merge --abort` + +## 使用場景 + +### 適用情境 + +- 執行 `git rebase` 時遇到衝突 +- 執行 `git merge` 時遇到衝突 +- 需要系統化地處理多個衝突檔案 +- 不確定如何正確解決衝突 + +### 處理策略 + +**簡單衝突:** +- 完全採用一方的修改(ours 或 theirs) +- 直接使用對應策略: + ```bash + git checkout --ours <檔案> # 保留當前分支的版本 + git checkout --theirs <檔案> # 採用合併進來的版本 + ``` + +**複雜衝突:** +- 需要手動合併雙方的修改 +- 仔細檢視衝突區塊的上下文 +- 整合兩邊的邏輯變更 + +## 工作流程範例 + +``` +[執行 rebase 時遇到衝突] + +User: 我在 rebase 時遇到衝突了,幫我解決。 + +Agent: 偵測到 rebase 衝突,有 2 個檔案需要解決: + 1. src/auth/login.ts + 2. README.md + +開始解決第一個衝突... + +檔案:src/auth/login.ts +衝突位置:第 15 行 + +衝突內容比對: +<<<<<<< HEAD (當前分支) +if (user.verified) { + return authenticateUser(user) +} +======= +if (user.isVerified && user.active) { + return authenticate(user) +} +>>>>>>> feature/new-auth + +Agent: [使用 AskUserQuestion] + 要如何解決這個衝突? + 選項: + 1. 保留當前版本(user.verified) + 2. 採用新版本(user.isVerified && user.active) + 3. 整合:保留 isVerified 和 active 檢查,使用 authenticateUser + 4. 其他自訂方案 + +User: [選擇選項 3] + +Agent: 已解決 login.ts 並標記為已解決。 + +繼續處理 README.md... +[展示衝突並詢問] + +User: [選擇保留雙方的文件更新] + +Agent: 所有衝突已解決,執行 git rebase --continue + Rebase 成功完成! + +User: [確認結果並繼續開發] +``` + +## 注意事項 + +### 安全檢查 + +- **資訊透明化**:在詢問使用者前,務必先展示完整的衝突內容和上下文 +- **明確選項**:提供所有可能的解決方案,包括手動整合的不同組合方式 +- 解決衝突前先確認了解雙方的修改意圖 +- 不確定時使用 AskUserQuestion 詢問使用者應該保留哪個版本 +- 解決後建議執行測試確保功能正常 + +### 常見錯誤 + +**避免:** +- 未展示衝突詳細內容就直接詢問使用者如何解決 +- 手動整合選項不夠明確(例如只提供「整合雙方」而不列出具體組合方式) +- 直接刪除所有衝突標記而不檢視內容 +- 未理解程式碼脈絡就決定保留哪個版本 +- 解決衝突後未執行測試 + +**推薦:** +- 先展示完整的衝突資訊,再使用 AskUserQuestion 提供明確選項 +- 列出所有可能的解決方案,包括不同的整合順序 +- 仔細閱讀衝突區塊的上下文 +- 理解兩個版本的差異原因 +- 可能的話整合雙方的優點 +- 解決後執行相關測試 + +### 特殊情況 + +**二進位檔案衝突:** +```bash +# 只能選擇其中一個版本 +git checkout --ours <二進位檔案> +# 或 +git checkout --theirs <二進位檔案> +``` + +**檔案刪除衝突:** +- 一方修改,一方刪除 +- 需要判斷是否應該保留或刪除該檔案 + +## 整合其他工具 + +解決衝突後建議: +- 使用 `reviewers:requesting-code-review` 檢視解決方案 +- 執行專案的測試套件