git cherry-pick

1. 你在 A 分支 写完代码 → 提交

bash 复制代码
git add .
git commit -m "修复xx功能"

2. 查看 commit 号(你说的:git log)

bash 复制代码
git log

找到你刚才的提交 ID:

复制代码
d67b3489e05abb139f8d14e8ac61c5862884d3

复制这一串

3. 切换到目标分支 B

bash 复制代码
git checkout B

4. 把 A 分支的那个提交精准搬运到 B 分支

bash 复制代码
git cherry-pick d67b3489e05abb139f8d14e8ac61c5862884d3

5. 完成!

现在 B 分支就只有你这次的修改,不会把整个 A 分支合进来。


你总结的流程是完全正确的!

我再帮你复述一遍,确保你 100% 懂:

  1. A 分支改代码
  2. commit
  3. git log 拿到 commit 号
  4. 切到 B 分支
  5. git cherry-pick commit号
  6. 完成!

这就是 git cherry-pick 最标准、最安全、最常用的流程 ✅


小补充(遇到冲突怎么办)

如果 cherry-pick 时报冲突:

  1. 打开文件解决冲突
bash 复制代码
git add .
git cherry-pick --continue

相关推荐
减瓦1 天前
Windows 环境使用 Git Bash 最佳实践
windows·git
史呆芬1 天前
CodeX多仓库提交Skill搭建
git·后端·openai
城东1 天前
Git使用[原意要新建分支提交但是误提交到原来分支恢复办法]
git·原意要新建分支提交·但是误提交到原来分支
开发者联盟league1 天前
git 压缩本地最近多个commit
git
赵庆明老师2 天前
Vben精讲:04-了解VSCode中的Git
ide·git·vscode
Irissgwe2 天前
第 5 篇:Git 分支基础:branch、checkout、merge 和冲突解决
git
liberalhumblehopeful2 天前
git代码管理-分支差距过大如何进行同步
git
一只楚楚猫2 天前
一篇文章入门Git工具
git
Irissgwe2 天前
第 6 篇:Git 分支进阶:分支策略、stash、bugfix 和 feature 开发
git
wok1572 天前
Git Bash 执行中文命令报错 127:MSYS 参数编码 bug 排查与修复
git·bug·bash