经常需要不同的repo 或者不同的branch ,都需要提交一份patch,这个时候,使用git cherry-pick 就很方便。
具体使用方式如下,
(一)不同的repo
假设,
当前patch所在,source_repo/source_branch, url 是url_source
推送code 目标位置,target_repo/target_branch, url 是url_target
在target_repo/target_branch这个目录下,执行如下操作,
1.git remote add source_patch_repo url_source
source_patch_repo 只是个name ,可以随意定义
在本地add 一个remote repo
2.git fetch source_patch_repo
将source repo 信息fetch 到本地
3.git log source_patch_repo/source_branch
这里只是为了获取commit id,比如commit 343bb9b7db713ada0977d5fc405beba02e082f0f
4.git cherry-pick commit_id
比如,git cherry-pick 343bb9b7db713ada0977d5fc405beba02e082f0f
5.git push target_repo target_branch
(二)相同的repo ,不同的branch
假设,
当前patch所在,source_repo/source_branch,
推送code 目标位置,source_repo/target_branch,
在source_repo/target_branch这个目录下,执行如下操作,
1.git log source_repo/source_branch
这里只是为了获取commit id,比如commit 343bb9b7db713ada0977d5fc405beba02e082f0f
2.git cherry-pick commit_id
比如,git cherry-pick 343bb9b7db713ada0977d5fc405beba02e082f0f
3.git push source_repo target_branch