技能 git-advanced-workflows
📦

git-advanced-workflows

安全

掌握進階 Git 工作流程

也可从以下获取: wshobson

開發者常在複雜的 Git 操作上遇到困難,例如歷史記錄重寫和從錯誤中恢復。此技能提供進階 Git 命令的綜合指南,包括 rebase、cherry-pick、bisect、worktrees 和 reflog,以保持乾淨的歷史記錄並從任何情況中恢復。

支持: Claude Codex Code(CC)
🥉 72 青铜
1

下载技能 ZIP

2

在 Claude 中上传

前往 设置 → 功能 → 技能 → 上传技能

3

开启并开始使用

测试它

正在使用“git-advanced-workflows”。 How do I clean up my commit history before creating a pull request?

预期结果:

使用互動式 rebase 來清理你的 commits。執行 'git rebase -i main' 來編輯你最後的數個 commits。你可以 squash (s) 多個 commits 在一起、reword (r) commit messages,或 drop (d) 不需要的 commits。在重寫歷史記錄之前,務必先用 'git branch backup-branch' 建立備份分支。

正在使用“git-advanced-workflows”。 I accidentally reset my branch and lost my commits. How can I recover them?

预期结果:

使用 git reflog 來尋找你遺失的 commits。執行 'git reflog' 來查看所有 ref 更新的歷史記錄。找到重置前的 commit hash,然後用 'git reset --hard <commit-hash>' 恢復,或用 'git branch recovered-branch <commit-hash>' 建立分支。Reflog 會保留 90 天的歷史記錄。

安全审计

安全
v1 • 2/25/2026

All static findings are false positives. The skill is a documentation guide for Git commands - the flagged 'external_commands' are Git examples in markdown code blocks, 'filesystem' findings are legitimate worktree relative paths, and 'weak cryptographic algorithm' was a misidentification. This is safe, legitimate educational content.

1
已扫描文件
415
分析行数
0
发现项
1
审计总数
未发现安全问题

检测到的模式

External Command Detection (False Positive)Path Traversal Detection (False Positive)Cryptographic Algorithm Detection (False Positive)
审计者: claude

质量评分

38
架构
100
可维护性
87
内容
32
社区
100
安全
100
规范符合性

你能构建什么

在 pull request 前清理功能分支

使用互動式 rebase 來 squashing、重新排序和清理 commit message,然後合併到 main 分支

找出 bug 引入點

使用 git bisect 二進位搜尋快速定位哪個 commit 引入了回歸問題

從 Git 錯誤中恢復

使用 reflog 恢復意外刪除或重置的 commits 或 branches

试试这些提示

互動式 rebase 指南
Help me use interactive rebase to clean up my feature branch. I want to squash my last 5 commits into one clean commit with a good message.
Cherry-pick 一個 commit
How do I cherry-pick a specific commit from another branch onto my current branch? The commit hash is abc123.
找出有 bug 的 commit
I need to find which commit introduced a bug. How do I use git bisect to systematically search through my commit history?
Worktree 設定
Show me how to set up a Git worktree so I can work on a hotfix while keeping my current feature work intact.

最佳实践

  • 在執行 rebase 或 reset 等破壞性 Git 操作之前,務必建立備份分支
  • 推送重寫的歷史記錄時使用 --force-with-lease 而非 --force,以防止覆蓋他人的工作
  • 在 rebase 操作後執行測試,確保重寫的歷史記錄沒有破壞任何功能

避免

  • 對其他開發者已經 pull 的公共分支進行 rebasing - 這會導致協作者的歷史記錄衝突
  • 在未檢查其他人是否已推送新變更到遠端的情況下使用 'git push --force'
  • 在未先 stage 或 stash 變更的情況下,在髒的工作目錄上執行 git bisect

常见问题

rebase 和 merge 有什麼區別?
Rebase 會重寫 commit 歷史記錄,將你的 commits 應用到另一個分支的頂部,建立線性歷史記錄。Merge 在不改變歷史記錄的情況下合併分支。在推送前使用 rebase 進行本地清理,使用 merge 將已完成的工作整合到共享分支中。
什麼時候應該使用 cherry-pick 而不是 merge?
當你只需要另一個分支的特定 commits 而不是整個分支歷史記錄時,使用 cherry-pick。這對於在不合併所有變更的情況下將 hotfixes 應用到多個 release branches 很有用。
git bisect 是如何運作的?
Git bisect 使用二進位搜尋來找出引入 bug 的 commit。你標記一個已知有問題的 bad commit 和一個 good commit,然後 Git 會 checkout 中間的 commits。你測試每一個並標記 good 或 bad,直到找到第一個 bad commit。
什麼是 Git worktree,什麼時候應該使用它?
Worktree 讓你可以同時在不同的目錄中 checkout 多個 branches。當你需要同時處理多個功能或修復而无需 stash 當前工作時使用它。
reflog 會保留已刪除的 commit 歷史記錄多久?
Reflog 預設保留 90 天的歷史記錄,或在 ref 被垃圾回收之前。這提供了一個安全網,可以在這個期間內恢復遺失的 commits 或 branches。
重寫 Git 歷史記錄安全嗎?
對於尚未共享的本地分支,重寫歷史記錄是安全的。對於共享分支,只有在絕對必要時才重寫,並始終使用 'git push --force-with-lease' 以避免覆蓋他人的工作。

开发者详情

文件结构

📄 SKILL.md