git进阶 之 cherry-pick
2020-05-29 本文已影响0人
诺之林
定义
-
Apply the changes introduced by some existing commits
-
Given one or more existing commits, apply the change each one introduces, recording a new commit for each
效果
a - b - c - d Master
\
e - f - g Feature
git checkout master
git cherry-pick f
a - b - c - d - f Master
\
e - f - g Feature
场景
- For example, say a commit is accidently made to the wrong branch. You can switch to the correct branch and cherry-pick the commit to where it should belong
Team collaboration
Bug hotfixes
Undoing changes and restoring lost commits
使用
# 单次提交
git cherry-pick <commitHash>
# 多次提交
git cherry-pick <HashA> <HashB>
# 区间提交 左开右闭
git cherry-pick A..B
# 区间提交 左闭右闭
git cherry-pick A^..B
# 只更新工作区和暂存区 不产生新的提交
git cherry-pick -n