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 last 3 commits were pushed in a single pull requests and I'm supposed to move them into separate branches each. I tried reverting and creating new branches but it got messed up and I'm back at square 1.
Asked
Active
Viewed 752 times
3
-
Wait...do you mean each commit has to be sitting on top of the same base in separate branches, or do you need three branche will successive commits? – Tim Biegeleisen Apr 05 '16 at 11:12
-
what are you exactly trying to do? – peeyush pathak Apr 05 '16 at 11:12
-
just explain step by step what did you do? – peeyush pathak Apr 05 '16 at 11:14
1 Answers
1
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

Tim Biegeleisen
- 502,043
- 27
- 286
- 360