提示:本网站现在为维护调试状态

Advanced Git Workflows

Choyeon
Choyeon
Aug 29, 2026 1 min read 368 Views
347 words 1,678 chars Updated Nov 8, 2026
Advanced Git Workflows
Table of contents

Basic add/commit/push handles daily collaboration. Advanced commands give precise history control and efficient debugging.

Interactive Rebase for Clean History

Use reword/squash/fixup/drop directives to rewrite sequences: merge WIP commits, fix messages, remove debug code, keep main branch history clean.

#!/usr/bin/env bash
set -euo pipefail

# 1. Interactive Rebase: squash最近5条WIP,reword命名
git rebase -i HEAD~5 <<EOF
pick   a1b2c3d feat: add login API
reword b3e4f5g fix typo in user model
squash c6h7i8j wip: add test cases
fixup  d9k0l1m fix lint issues
drop   e2n3o4p tmp debug log
EOF

# 2. Cherry-pick: 跨分支移植hotfix
git checkout release/2.0
git cherry-pick -x a1b2c3d
# 多个提交合入暂存区手动合并后一次性提交:
# git cherry-pick --no-commit b3e4f5g c6h7i8j
# git cherry-pick --continue / --abort

# 3. Bisect: 二分找引入Bug的提交
git bisect start
git bisect bad HEAD
git bisect good v1.8.0
git bisect run pytest tests/test_auth.py -x
# Output: a1b2c3d is the first bad commit
git bisect reset

# 4. Reflog救援
git reflog --date=iso | head -20
# git reset --hard HEAD@{3}

# 5. 批量修复作者信息
git filter-branch -f --env-filter '
if [ "$GIT_AUTHOR_EMAIL" = "old@example.com" ]; then
    export GIT_AUTHOR_NAME="Correct Name" GIT_AUTHOR_EMAIL="new@example.com"
    export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
fi
' HEAD

Bisect for Binary-Search Bug Hunting

When regression appeared mysteriously, Bisect binary-searches the first bad commit. Combined with test scripts it finds the issue in minutes with zero manual effort.

Command Purpose Risk Level Best For
rebase -i Rewrite history Medium (local only) Before merge request
cherry-pick Port commits Low (new hashes) Backport hotfixes
bisect Binary search Very Low (read-only) Regression hunting
reflog Op history Zero (read-only) Disaster recovery
filter-branch Bulk rewrite Very High (hash change) Author info fixes

Best Practices

Golden rule: never rebase pushed commits. Before destructive ops, tag safety net with git tag backup-$(date +%Y%m%d).

X微博Telegram

About the author

Poll

你最希望 Rosetta 优先加入哪项功能?

社区投票(演示数据,可后台删除)

Comments (3)

0 / 3000
云端漫步
云端漫步cloud-notes.cloudSep 21, 2026

太好了!终于有人把 CI/CD 的完整流程讲清楚了,之前看了好多文章都是只讲一半,跟着这篇一步步跑通了整个流水线。

测试小瓢虫
测试小瓢虫Sep 21, 2026

建议可以再加一下关于成本优化的部分,云上资源如果不注意优化的话,账单真的会吓死个人。

考研加油鸭
考研加油鸭kaoyan-journey.xyzSep 20, 2026

非常棒的文章,就是希望能再深入讲讲容器镜像优化这块,我现在的镜像打包出来都 1G 多,感觉太臃肿了。

Related posts

CI/CD Pipeline Design: GitHub Actions + Cache + Matrix Build

CI/CD Pipeline Design: GitHub Actions + Cache + Matrix Build

Production GitHub Actions pipeline from scratch: npm/pip cache, multi-version Node/Python matrix builds, Docker layer caching, Lint+Test+Build+Publish stages, conditional execution, env matrix, failure retry, and release gating best practices. Complete workflow YAML included.

1 min read
Monorepo Toolchain: Turborepo + pnpm workspace

Monorepo Toolchain: Turborepo + pnpm workspace

Complete monorepo guide for large fullstack projects: pnpm workspace for unified dependency install + linking, Turborepo for task orchestration, incremental builds and remote caching. Compares Nx/Lerna, includes code sharing and release best practices.

1 min read
Docker Compose Production Deployment Guide

Docker Compose Production Deployment Guide

Deep dive into Docker Compose production best practices: multi-stage builds, health checks, resource limits, logging, network isolation, and secrets management for reliable container deployments.

1 min read
Prompt Engineering 101: Few-Shot + CoT + Structured Output

Prompt Engineering 101: Few-Shot + CoT + Structured Output

Systematic prompt engineering primer covering three core techniques: Few-Shot examples for style injection, Chain-of-Thought for complex reasoning, JSON Schema enforced structured outputs for downstream systems. Includes real templates and anti-patterns.

1 min read
Alembic Deep Dive: Migrations, Autogenerate, and Branch Merging

Alembic Deep Dive: Migrations, Autogenerate, and Branch Merging

Comprehensive Alembic (official SQLAlchemy migration tool) guide: env.py setup, autogenerate detecting model changes (fields, indexes, constraints), batch scripts, downgrade rollback strategies, plus standard SOP for multi-developer migration branch conflicts and divergent head merging, with production deploy checklist.

1 min read
Test Pyramid: Unit/Integration/E2E Ratios & Implementation

Test Pyramid: Unit/Integration/E2E Ratios & Implementation

Systematic test pyramid breakdown: bottom unit tests (many, fast, mock isolated), middle integration tests (real service/db/message interaction), top E2E tests (few, critical user flows). Recommended ratio 70/20/10, with coverage metrics and implementation playbook.

1 min read