git cherry pick 使用指南

2021-07-28 03:04:27 字數 1686 閱讀 9599

git cherry-pick可以選擇某乙個分支中的乙個或幾個commit(s)來進行操作。例如,假設我們有個穩定版本的分支,叫v2.0,另外還有個開發版本的分支v3.0,我們不能直接把兩個分支合併,這樣會導致穩定版本混亂,但是又想增加乙個v3.0中的功能到v2.0中,這裡就可以使用cherry-pick了,其實也就是對已經存在的commit 進行再次提交.

簡單用法:

git cherry-pick

注意:當執行完 cherry-pick 以後,將會生成乙個新的提交;這個新的提交的雜湊值和原來的不同,但標識名一樣;

例如:$ git checkout v2.0分支

$ git cherry-pick 38361a55 # 這個 38361a55 號碼,位於v3.0分支中:

$ git log

commit 38361a55138140827b31b72f8bbfd88b3705d77a

author: justin justin@***.com

date: sat dec 10 00:11:44 2016 +0800

1. 如果順利,就會正常提交。結果:

finished one cherry-pick.

on branch v2.0分支

your branch is ahead of 'origin/old_cc' by 3 commits.

2. 如果在cherry-pick 的過程中出現了衝突

automatic cherry-pick failed.

after resolving the conflicts,mark the corrected paths with 'git add ' or 'git rm 'and commit the result with:

git commit -c 15a2b6c61927e5aed6111de89ad9dafba939a90b

或者:

就跟普通的衝突一樣,手工解決:

2.1 $ git status # 看哪些檔案出現衝突

2.4 git commit -c 《新的commit號碼》

2.5 再次cherry-pick剩餘commit

error: a cherry-pick or revert is already in progress

hint: try "git cherry-pick (--continue | --quit | --abort)"

fatal: cherry-pick failed

則執行對應操作:

git cherry-pick --continue

git cherry-pick --quit

git cherry-pick --abort

命令集合:

前者表示把到之間(左開右閉,不包含start-commit-id)的提交cherry-pick到當前分支;

後者有"^"標誌的表示把到之間(閉區間,包含start-commit-id)的提交cherry-pick到當前分支。

其中,到只需要commit-id的前6位即可,並且在時間上必須早於

注:以上合併,需要手動push**。

from: 

git cherry pick使用小記

cherry pick,顧名思義 摘櫻桃。如果說每一次commit是一顆櫻桃,那麼你可以通過cherry pick命令將這一顆櫻桃採摘到另外一顆櫻桃樹 branch 上。通常使用方式有如下兩種 1 git cherry pick 997367b commit id commit id可通過git l...

Git cherry pick 使用總結

假設我們有 branch 01 和 branch 02 兩個開發分支,那麼我們怎麼把 branch 01 上的乙個或者幾個commit合併到 branch 02 上呢?假設 branch 01 有如下兩個commit的hash值 59e7e6545a2eda9b82f5795173792e6490c...

git cherry pick使用詳解

cherry pick 和它的名稱一樣,精心挑選,挑選乙個我們需要的 commit 進行操作。它可以用於將在其他分支上的 commit 修改,移植到當前的分支。想在某個穩定版本上,新增乙個剛開發完成的版本中的功能。就可以使用 cherry pick 命令,將這個功能相關的 commit 提取出來,合...