git-rebase-workflow
Git Rebase 工作流
将当前功能分支 rebase 到最新的目标分支(通常是 master/main),保持线性提交历史。
使用场景
- 功能分支落后于 master,需要同步最新代码
- 提交 MR/PR 前保持提交历史整洁
- 避免使用
git merge产生的合并提交
前置检查
-
确认当前分支状态:
git branch -v git status -
确认工作区干净(无未提交的更改)
Rebase 流程
1. 获取最新代码
git fetch origin <目标分支>
2. 执行 Rebase
git rebase origin/<目标分支>
3. 解决冲突(如有)
如果出现冲突,按以下步骤处理:
-
查看冲突文件:
git status -
查看冲突详情:
grep -n "<<<<<<< HEAD\|=======\|>>>>>>>" <冲突文件> -
解决冲突策略:
-
保留目标分支版本(ours):
git checkout --ours <文件路径> -
保留当前分支版本(theirs):
git checkout --theirs <文件路径> -
手动编辑: 直接修改冲突文件,删除冲突标记
-
-
标记冲突已解决:
git add <文件路径> -
继续 rebase:
git rebase --continue -
如需中止 rebase:
git rebase --abort
4. 推送更新
git push origin <当前分支> --force-with-lease
注意:必须使用
--force-with-lease安全地强制推送
常见问题
冲突解决原则
- 版本号冲突: 通常保留较新的版本
- API 变更: 根据具体情况分析,询问用户意图
- 配置变更: 评估变更影响,选择合适的版本
安全建议
- rebase 前确保有备份或已推送的分支
- 不要对公共分支(如 master)执行 rebase
- 使用
--force-with-lease而非--force推送 - 如有不确定,先询问用户选择
完整示例
# 1. 检查状态
git branch -v
git status
# 2. 获取最新代码
git fetch origin master
# 3. 执行 rebase
git rebase origin/master
# 4. 解决冲突(如需要)
# - 查看冲突: git status
# - 保留 ours/theirs 或手动编辑
# - git add <文件>
# - git rebase --continue
# 5. 推送
git push origin feature-branch --force-with-lease
More from nangongwentian-fe/agent-skills
persistent-memory
通用跨会话记忆协议(Universal Memory Protocol)。让所有 AI 编程工具共享同一套记忆系统。适用 Claude Code / Cursor / Aider / Cline / Codex / Trae / OpenCode。能力:智能分类 / FSRS 衰减 / 月度压缩 / 多层检索。触发:用户说"记住";问"之前";检测到敏感信息;会话结束。
23exa-unified-research
Use this skill for ANY web research task — looking up companies, finding people, searching for code examples or API docs, reading tech blogs, finding academic papers, checking SEC filings or financial reports, or gauging social media sentiment. Covers any question that requires searching the internet for current information. Exa provides neural/semantic search that returns higher-quality, better-structured results than simple keyword search. Load this skill whenever the user asks you to search, research, find, look up, or investigate anything online — even if you think you can handle it with built-in search tools, this skill will produce significantly better results.
10code-review-uncommitted
对 git 中未提交的代码变更进行多维度 code review,包括项目规范合规性、Bug 扫描、代码注释合规性、组件封装/架构设计合理性审查,并通过置信度评分过滤误报。当用户要求 review 未提交的代码、review 当前改动、或使用 /code-review-uncommitted 时触发。
8reflect-and-remember
|
4codex-cli
Delegate tasks to the local OpenAI Codex CLI (`codex exec`, `codex review`, `codex cloud exec`). Use this skill whenever the user asks to run Codex, delegate a task to Codex, use OpenAI's agent, do a Codex review, or mentions 'codex' in any form — including phrases like '用 codex 跑一下', '让 codex 帮忙', 'run this with codex', 'codex exec', 'codex review', 'send to codex cloud'. Also trigger when the user wants a second opinion from another AI agent on code changes, or wants to run a task in a sandboxed OpenAI environment.
1web-content-fetcher
>
1