git-advancedlisted
Install: claude install-skill ryukyagamilight/terminal-skills
# Git 高级操作
## 概述
分支策略、rebase、cherry-pick、hooks 等高级 Git 技能。
## 分支管理
### 分支操作
```bash
# 创建分支
git branch feature/new-feature
git checkout -b feature/new-feature
git switch -c feature/new-feature
# 切换分支
git checkout main
git switch main
# 删除分支
git branch -d feature/merged
git branch -D feature/unmerged # 强制删除
# 删除远程分支
git push origin --delete feature/old
# 重命名分支
git branch -m old-name new-name
# 查看分支
git branch -a # 所有分支
git branch -v # 带最��提交
git branch --merged # 已合并分支
git branch --no-merged # 未合并分支
```
### 分支追踪
```bash
# 设置上游分支
git branch --set-upstream-to=origin/main main
git push -u origin feature/new
# 查看追踪关系
git branch -vv
```
## Rebase 操作
### 基础 rebase
```bash
# 变基到 main
git checkout feature
git rebase main
# 交互式 rebase
git rebase -i HEAD~5
git rebase -i main
# 交互式命令
# pick - 保留提交
# reword - 修改提交信息
# edit - 修改提交内容
# squash - 合并到上一个提交
# fixup - 合并但丢弃提交信息
# drop - 删除提交
# 继续/中止 rebase
git rebase --continue
git rebase --abort
git rebase --skip
```
### 合并提交
```bash
# 合并最近 3 个提交
git rebase -i HEAD~3
# 将后两个 pick 改为 squash 或 fixup
# 修改历史提交信息
git rebase -i HEAD~3
# 将 pick 改为 reword
```
## Cherry-pick
```bash
# 选择单个提交
git cherry-pick commit-hash
# 选择多个提交
git cherry-pick commit1 commit2 commit3
# 选择范围(不包含起始)
git cherry-pick start-commit..end-commit
# 不自动提交
git cherry-pick -n commit-hash
# 解决冲突后继续
git cherry-pick --continue
git cherry-pick --abort
```
## Stash 暂存
``