Split branch into one branch per commit

前端 未结 1 1319
庸人自扰
庸人自扰 2021-01-26 23:26

In this project I\'m working on, I\'m supposed to commit my progress to a repo using pull requests, and every commit has to be in a different branch. The problem is that the las

相关标签:
1条回答
  • 2021-01-26 23:55

    In this answer, I will assume that your branch is called feature, and that feature has the three commits in question as its three most recent commits.

    Create a new branch from feature:

    git checkout -b onecommit
    

    Nuke the two most recent commits, leaving the first of three commits remaining:

    git reset --hard HEAD~2
    

    Now push this branch containing just the first commit to your repo:

    git push origin onecommit
    

    To obtain a branch with just two commits you would follow a similar process:

    git checkout -b twocommits
    git reset --hard HEAD~1
    git push origin twocommits
    
    0 讨论(0)
提交回复
热议问题