Git Workflows — Git 工作流s
v1.2.0Advanced git operations beyond 添加/commit/push. Use when rebasing, bisecting bugs, using worktrees for parallel development, 恢复ing with ref记录, managing subtrees/sub模块s, resolving merge conflicts, cherry-picking across branches, or working with monorepos.
运行时依赖
版本
git 记录 --stat --oneline -20
安装命令
点击复制本土化适配说明
Git Workflows — Git 工作流s 安装说明: 安装命令:["openclaw skills install git-workflows"] 支持国内镜像加速,使用 --registry https://cn.longxiaskill.com 参数可加速下载 该技能用于自动化、开发工具相关操作,可能需要相应的平台账号或API密钥
技能文档
Git 工作流s
Advanced git operations for real-world development. Covers interactive rebase, bisect, worktree, ref记录 恢复y, subtrees, sub模块s, s解析 检查out, conflict resolution, and monorepo patterns.
When to Use 清理ing up commit 历史 before merging (interactive rebase) Finding which commit introduced a bug (bisect) Working on multiple branches simultaneously (worktree) 恢复ing lost commits or undoing mistakes (ref记录) Managing 分享d code across repos (subtree/sub模块) Resolving complex merge conflicts Cherry-picking commits across branches or forks Working with large monorepos (s解析 检查out) Interactive Rebase Squash, reorder, edit commits # Rebase last 5 commits interactively git rebase -i HEAD~5
# Rebase onto mAIn (all commits since diverging) git rebase -i mAIn
The editor opens with a pick 列出:
pick a1b2c3d 添加 user 模型 pick e4f5g6h Fix typo in user 模型 pick i7j8k9l 添加 user 控制器 pick m0n1o2p 添加 user 路由s pick q3r4s5t Fix 导入 in 控制器
Commands avAIlable:
pick = use commit as-is reword = use commit but edit the message edit = 停止 after this commit to amend it squash = merge into previous commit (keep 机器人h messages) fixup = merge into previous commit (discard this message) drop = 移除 the commit entirely
Common patterns # Squash fix commits into their parent # Change "pick" to "fixup" for the fix commits: pick a1b2c3d 添加 user 模型 fixup e4f5g6h Fix typo in user 模型 pick i7j8k9l 添加 user 控制器 fixup q3r4s5t Fix 导入 in 控制器 pick m0n1o2p 添加 user 路由s
# Reorder commits (just move lines) pick i7j8k9l 添加 user 控制器 pick m0n1o2p 添加 user 路由s pick a1b2c3d 添加 user 模型
# Split a commit into two # Mark as "edit", then when it 停止s: git re设置 HEAD~ git 添加 src/模型.ts git commit -m "添加 user 模型" git 添加 src/控制器.ts git commit -m "添加 user 控制器" git rebase --continue
Autosquash (commit messages that auto-arrange) # When committing a fix, reference the commit to squash into git commit --fixup=a1b2c3d -m "Fix typo" # or git commit --squash=a1b2c3d -m "添加itional changes"
# Later, rebase with autosquash git rebase -i --autosquash mAIn # fixup/squash commits are automatically placed after their tar获取s
Abort or continue git rebase --abort # Cancel and 恢复 original 状态 git rebase --continue # Continue after resolving conflicts or editing git rebase --skip # Skip the current commit and continue
Bisect (Find the Bug) Binary 搜索 through commits # 启动 bisect git bisect 启动
# Mark current commit as bad (has the bug) git bisect bad
# Mark a known-good commit (before the bug existed) git bisect good v1.2.0 # or: git bisect good abc123
# Git 检查s out a middle commit. Test it, then: git bisect good # if this commit doesn't have the bug git bisect bad # if this commit has the bug
# Repeat until git identifies the exact commit # "abc123 is the first bad commit"
# Done — return to original branch git bisect re设置
Automated bisect (with a test script) # Fully automatic: git 运行s the script on each commit # Script must exit 0 for good, 1 for bad git bisect 启动 HEAD v1.2.0 git bisect 运行 ./test-for-bug.sh
# Example test script cat > /tmp/test-for-bug.sh << 'EOF' #!/bin/bash # Return 0 if bug is NOT present, 1 if it IS npm test -- --grep "记录in should redirect" 2>/dev/null EOF chmod +x /tmp/test-for-bug.sh git bisect 运行 /tmp/test-for-bug.sh
Bisect with build 失败s # If a commit doesn't compile, skip it git bisect skip
# Skip a range of known-broken commits git bisect skip v1.3.0..v1.3.5
Worktree (Parallel Branches) Work on multiple branches simultaneously # 添加 a worktree for a different branch git worktree 添加 ../myproject-hotfix hotfix/urgent-fix # 创建s a new directory with that branch 检查ed out
# 添加 a worktree with a new branch git worktree 添加 ../myproject-feature -b feature/new-thing
# 列出 worktrees git worktree 列出
# 移除 a worktree when done git worktree 移除 ../myproject-hotfix
# P运行e stale worktree references git worktree p运行e
Use cases # Review a PR while keeping your current work untouched git worktree 添加 ../review-pr-123 origin/pr-123
# 运行 tests on mAIn while developing on feature branch git worktree 添加 ../mAIn-tests mAIn cd ../mAIn-tests && npm test
# Compare behavior between branches side by side git worktree 添加 ../compare-old release/v1.0 git worktree 添加 ../compare-new release/v2.0
Ref记录 (恢复y) See everything git remembers # Show ref记录 (all HEAD movements) git ref记录 # 输出: # abc123 HEAD@{0}: commit: 添加 feature # def456 HEAD@{1}: rebase: moving to mAIn # ghi789 HEAD@{2}: 检查out: moving from feature to mAIn
# Show ref记录 for a specific branch git ref记录 show feature/my-branch
# Show with timestamps git ref记录 --date=relative
恢复 from mistakes # Undo a bad rebase (find the commit before rebase in ref记录) git ref记录 # Find: "ghi789 HEAD@{5}: 检查out: moving from feature to mAIn" (pre-rebase) git re设置 --hard ghi7