[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-8926aeac-176f-45ab-85e0-a35bdf8288bd":3,"$fwmgCgax2J6f5RRoBQQzq_BYukeQjcbys49OZb22sNxQ":44},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"8926aeac-176f-45ab-85e0-a35bdf8288bd","git-advanced-workflows","精通高级Git技巧，以保持干净的历史记录，有效协作，并自信地应对任何情况。","cat_prod_automation","mod_productivity","sickn33,productivity","---\nname: git-advanced-workflows\ndescription: \"Master advanced Git techniques to maintain clean history, collaborate effectively, and recover from any situation with confidence.\"\nrisk: critical\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# Git Advanced Workflows\n\nMaster advanced Git techniques to maintain clean history, collaborate effectively, and recover from any situation with confidence.\n\n## Do not use this skill when\n\n- The task is unrelated to git advanced workflows\n- You need a different domain or tool outside this scope\n\n## Instructions\n\n- Clarify goals, constraints, and required inputs.\n- Apply relevant best practices and validate outcomes.\n- Provide actionable steps and verification.\n- If detailed examples are required, open `resources\u002Fimplementation-playbook.md`.\n\n## Use this skill when\n\n- Cleaning up commit history before merging\n- Applying specific commits across branches\n- Finding commits that introduced bugs\n- Working on multiple features simultaneously\n- Recovering from Git mistakes or lost commits\n- Managing complex branch workflows\n- Preparing clean PRs for review\n- Synchronizing diverged branches\n\n## Core Concepts\n\n### 1. Interactive Rebase\n\nInteractive rebase is the Swiss Army knife of Git history editing.\n\n**Common Operations:**\n- `pick`: Keep commit as-is\n- `reword`: Change commit message\n- `edit`: Amend commit content\n- `squash`: Combine with previous commit\n- `fixup`: Like squash but discard message\n- `drop`: Remove commit entirely\n\n**Basic Usage:**\n```bash\n# Rebase last 5 commits\ngit rebase -i HEAD~5\n\n# Rebase all commits on current branch\ngit rebase -i $(git merge-base HEAD main)\n\n# Rebase onto specific commit\ngit rebase -i abc123\n```\n\n### 2. Cherry-Picking\n\nApply specific commits from one branch to another without merging entire branches.\n\n```bash\n# Cherry-pick single commit\ngit cherry-pick abc123\n\n# Cherry-pick range of commits (exclusive start)\ngit cherry-pick abc123..def456\n\n# Cherry-pick without committing (stage changes only)\ngit cherry-pick -n abc123\n\n# Cherry-pick and edit commit message\ngit cherry-pick -e abc123\n```\n\n### 3. Git Bisect\n\nBinary search through commit history to find the commit that introduced a bug.\n\n```bash\n# Start bisect\ngit bisect start\n\n# Mark current commit as bad\ngit bisect bad\n\n# Mark known good commit\ngit bisect good v1.0.0\n\n# Git will checkout middle commit - test it\n# Then mark as good or bad\ngit bisect good  # or: git bisect bad\n\n# Continue until bug found\n# When done\ngit bisect reset\n```\n\n**Automated Bisect:**\n```bash\n# Use script to test automatically\ngit bisect start HEAD v1.0.0\ngit bisect run .\u002Ftest.sh\n\n# test.sh should exit 0 for good, 1-127 (except 125) for bad\n```\n\n### 4. Worktrees\n\nWork on multiple branches simultaneously without stashing or switching.\n\n```bash\n# List existing worktrees\ngit worktree list\n\n# Add new worktree for feature branch\ngit worktree add ..\u002Fproject-feature feature\u002Fnew-feature\n\n# Add worktree and create new branch\ngit worktree add -b bugfix\u002Furgent ..\u002Fproject-hotfix main\n\n# Remove worktree\ngit worktree remove ..\u002Fproject-feature\n\n# Prune stale worktrees\ngit worktree prune\n```\n\n### 5. Reflog\n\nYour safety net - tracks all ref movements, even deleted commits.\n\n```bash\n# View reflog\ngit reflog\n\n# View reflog for specific branch\ngit reflog show feature\u002Fbranch\n\n# Restore deleted commit\ngit reflog\n# Find commit hash\ngit checkout abc123\ngit branch recovered-branch\n\n# Restore deleted branch\ngit reflog\ngit branch deleted-branch abc123\n```\n\n## Practical Workflows\n\n### Workflow 1: Clean Up Feature Branch Before PR\n\n```bash\n# Start with feature branch\ngit checkout feature\u002Fuser-auth\n\n# Interactive rebase to clean history\ngit rebase -i main\n\n# Example rebase operations:\n# - Squash \"fix typo\" commits\n# - Reword commit messages for clarity\n# - Reorder commits logically\n# - Drop unnecessary commits\n\n# Force push cleaned branch (safe if no one else is using it)\ngit push --force-with-lease origin feature\u002Fuser-auth\n```\n\n### Workflow 2: Apply Hotfix to Multiple Releases\n\n```bash\n# Create fix on main\ngit checkout main\ngit commit -m \"fix: critical security patch\"\n\n# Apply to release branches\ngit checkout release\u002F2.0\ngit cherry-pick abc123\n\ngit checkout release\u002F1.9\ngit cherry-pick abc123\n\n# Handle conflicts if they arise\ngit cherry-pick --continue\n# or\ngit cherry-pick --abort\n```\n\n### Workflow 3: Find Bug Introduction\n\n```bash\n# Start bisect\ngit bisect start\ngit bisect bad HEAD\ngit bisect good v2.1.0\n\n# Git checks out middle commit - run tests\nnpm test\n\n# If tests fail\ngit bisect bad\n\n# If tests pass\ngit bisect good\n\n# Git will automatically checkout next commit to test\n# Repeat until bug found\n\n# Automated version\ngit bisect start HEAD v2.1.0\ngit bisect run npm test\n```\n\n### Workflow 4: Multi-Branch Development\n\n```bash\n# Main project directory\ncd ~\u002Fprojects\u002Fmyapp\n\n# Create worktree for urgent bugfix\ngit worktree add ..\u002Fmyapp-hotfix hotfix\u002Fcritical-bug\n\n# Work on hotfix in separate directory\ncd ..\u002Fmyapp-hotfix\n# Make changes, commit\ngit commit -m \"fix: resolve critical bug\"\ngit push origin hotfix\u002Fcritical-bug\n\n# Return to main work without interruption\ncd ~\u002Fprojects\u002Fmyapp\ngit fetch origin\ngit cherry-pick hotfix\u002Fcritical-bug\n\n# Clean up when done\ngit worktree remove ..\u002Fmyapp-hotfix\n```\n\n### Workflow 5: Recover from Mistakes\n\n```bash\n# Accidentally reset to wrong commit\ngit reset --hard HEAD~5  # Oh no!\n\n# Use reflog to find lost commits\ngit reflog\n# Output shows:\n# abc123 HEAD@{0}: reset: moving to HEAD~5\n# def456 HEAD@{1}: commit: my important changes\n\n# Recover lost commits\ngit reset --hard def456\n\n# Or create branch from lost commit\ngit branch recovery def456\n```\n\n## Advanced Techniques\n\n### Rebase vs Merge Strategy\n\n**When to Rebase:**\n- Cleaning up local commits before pushing\n- Keeping feature branch up-to-date with main\n- Creating linear history for easier review\n\n**When to Merge:**\n- Integrating completed features into main\n- Preserving exact history of collaboration\n- Public branches used by others\n\n```bash\n# Update feature branch with main changes (rebase)\ngit checkout feature\u002Fmy-feature\ngit fetch origin\ngit rebase origin\u002Fmain\n\n# Handle conflicts\ngit status\n# Fix conflicts in files\ngit add .\ngit rebase --continue\n\n# Or merge instead\ngit merge origin\u002Fmain\n```\n\n### Autosquash Workflow\n\nAutomatically squash fixup commits during rebase.\n\n```bash\n# Make initial commit\ngit commit -m \"feat: add user authentication\"\n\n# Later, fix something in that commit\n# Stage changes\ngit commit --fixup HEAD  # or specify commit hash\n\n# Make more changes\ngit commit --fixup abc123\n\n# Rebase with autosquash\ngit rebase -i --autosquash main\n\n# Git automatically marks fixup commits\n```\n\n### Split Commit\n\nBreak one commit into multiple logical commits.\n\n```bash\n# Start interactive rebase\ngit rebase -i HEAD~3\n\n# Mark commit to split with 'edit'\n# Git will stop at that commit\n\n# Reset commit but keep changes\ngit reset HEAD^\n\n# Stage and commit in logical chunks\ngit add file1.py\ngit commit -m \"feat: add validation\"\n\ngit add file2.py\ngit commit -m \"feat: add error handling\"\n\n# Continue rebase\ngit rebase --continue\n```\n\n### Partial Cherry-Pick\n\nCherry-pick only specific files from a commit.\n\n```bash\n# Show files in commit\ngit show --name-only abc123\n\n# Checkout specific files from commit\ngit checkout abc123 -- path\u002Fto\u002Ffile1.py path\u002Fto\u002Ffile2.py\n\n# Stage and commit\ngit commit -m \"cherry-pick: apply specific changes from abc123\"\n```\n\n## Best Practices\n\n1. **Always Use --force-with-lease**: Safer than --force, prevents overwriting others' work\n2. **Rebase Only Local Commits**: Don't rebase commits that have been pushed and shared\n3. **Descriptive Commit Messages**: Future you will thank present you\n4. **Atomic Commits**: Each commit should be a single logical change\n5. **Test Before Force Push**: Ensure history rewrite didn't break anything\n6. **Keep Reflog Aware**: Remember reflog is your safety net for 90 days\n7. **Branch Before Risky Operations**: Create backup branch before complex rebases\n\n```bash\n# Safe force push\ngit push --force-with-lease origin feature\u002Fbranch\n\n# Create backup before risky operation\ngit branch backup-branch\ngit rebase -i main\n# If something goes wrong\ngit reset --hard backup-branch\n```\n\n## Common Pitfalls\n\n- **Rebasing Public Branches**: Causes history conflicts for collaborators\n- **Force Pushing Without Lease**: Can overwrite teammate's work\n- **Losing Work in Rebase**: Resolve conflicts carefully, test after rebase\n- **Forgetting Worktree Cleanup**: Orphaned worktrees consume disk space\n- **Not Backing Up Before Experiment**: Always create safety branch\n- **Bisect on Dirty Working Directory**: Commit or stash before bisecting\n\n## Recovery Commands\n\n```bash\n# Abort operations in progress\ngit rebase --abort\ngit merge --abort\ngit cherry-pick --abort\ngit bisect reset\n\n# Restore file to version from specific commit\ngit restore --source=abc123 path\u002Fto\u002Ffile\n\n# Undo last commit but keep changes\ngit reset --soft HEAD^\n\n# Undo last commit and discard changes\ngit reset --hard HEAD^\n\n# Recover deleted branch (within 90 days)\ngit reflog\ngit branch recovered-branch abc123\n```\n\n## Resources\n\n- **references\u002Fgit-rebase-guide.md**: Deep dive into interactive rebase\n- **references\u002Fgit-conflict-resolution.md**: Advanced conflict resolution strategies\n- **references\u002Fgit-history-rewriting.md**: Safely rewriting Git history\n- **assets\u002Fgit-workflow-checklist.md**: Pre-PR cleanup checklist\n- **assets\u002Fgit-aliases.md**: Useful Git aliases for advanced workflows\n- **scripts\u002Fgit-clean-branches.sh**: Clean up merged and stale branches\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,131,1504,"2026-05-16 13:20:00",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"效率工具","productivity","mdi-lightning-bolt-outline","文档处理、数据分析、自动化工作流",4,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"自动化","automation","mdi-robot-outline","工作流自动化、批处理",3,101,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":43},"fcea8ac0-913f-4a55-b38d-da029f6944f1","1.0.0","git-advanced-workflows.zip",3805,"uploads\u002Fskills\u002F8926aeac-176f-45ab-85e0-a35bdf8288bd\u002Fgit-advanced-workflows.zip","a7a0035b962fd44e9a4a362c15b1e4efa94264e76fc36cf5c4246ecfcb77f809","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":9873}]","2026-05-16 13:20:01",{"code":45,"message":46,"data":47},200,"success",{"items":48,"stats":49,"page":52},[],{"averageRating":50,"totalRatings":50,"ratingCounts":51},0,[50,50,50,50,50],{"limit":53,"offset":50,"hasMore":54,"nextOffset":53,"ratedOnly":16},15,false]