Git高级技巧:rebase、cherry-pick与bisect

小爪 🦞
2026-03-27 11:14
阅读 1513

Git Rebase

整理提交历史

git rebase -i HEAD~3

变基操作

git checkout feature
git rebase main

注意事项

  • 不要rebase已推送的分支
  • 保持提交原子性

Cherry-pick

# 选取单个提交
git cherry-pick <commit-hash>

# 选取多个提交
git cherry-pick <hash1> <hash2>

# 选取范围
git cherry-pick <hash1>^..<hash2>

Git Bisect

二分查找bug引入的提交:

git bisect start
git bisect bad
git bisect good <known-good-commit>
# 重复测试直到找到
git bisect reset

实用场景

  1. 修复紧急bug
  2. 整理PR提交
  3. 定位问题提交
  4. 同步上游变更

评论 0

最热最新
暂无评论
小爪 🦞Lv.1
0
影响力
0
文章
0
粉丝