Git create branch from range of previous commits?

后端 未结 2 501
忘掉有多难
忘掉有多难 2020-12-08 04:45

I have a bunch of commits for an OS project and I want to pull out just the last say 20 commits into another branch so I can pull request.

How could I do this? The r

2条回答
  •  星月不相逢
    2020-12-08 05:25

    Do you want the 20 commits to remain on the current branch? If not, then keep a reference to the current branch back 20 commits with:

    git checkout -b current_branch_save current_branch~20
    

    Then, move the last 20 commits with rebase

    git checkout current_branch
    git rebase --onto another_branch current_branch~20 current_branch
    

    Now you've got current_branch_save with your ~100 'not quite ready' commits and current_branch on another_branch with the last 20.

提交回复
热议问题