[Git] Cut commits onto other branches using git rebase –onto

Assume we have following branches:

We want to cut commit_3 and commit_4 on branch_2, onto master (commit_2). We can use the commands:

git checkout branch_2
git rebase --onto b111dc9 34e3359
(git rebase --onto new_base old_base)

The result looks like this:

If we want the commits but not to modify the incoming branch (branch_2 in the above example), we can use cherry-pick :

git checkout master
git cherry-pick 34e3359..321b7c0
(git cherry-pick start_commit_not_included..end_commit_included)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *