1

I've been working on a project and made good progress on several tasks.

I have been careful enough to keep all my changes for each task on their own individual commits.

Now, I want to issue pull requests for each commit individually, so there is only one commit per pull request.

What is the best way to go about this?

I've read it involves branches and cherry pick? I'd appreciate a tutorial, walkthrough or process flow.

Ideally I'd like to do this using a GUI, but first I'd appreciate the background of how and why.

Matt Sephton
  • 3,711
  • 4
  • 35
  • 46

2 Answers2

2

My recommendation is also to use separate branch for each pull request & cherry-pick your commits to those separate branches.

For that I will give you the process with this below example, You have your master branch without any of your feature commits & you have your Dev branch with all of your commits A,B,C,D

master

Dev => A,B,C,D

First you have to checkout to your master branch

git checkout master

Then create FEATURE-A branch from master

git checkout -b FEATURE-A

Then cherry-pick your commit A to FEATURE-A branch

git cherry-pick A #A is the hash value of your commit. Eg- 2f8b782

Now you have your FEATURE-A branch with only the commit A. So now you can push your FEATURE-A branch to origin & create the pull request

git push origin FEATURE-A

And repeat the same process to other commits as well.

Hope you understand what I'm trying to tell you. I tried my best to keep this as simple as possible. If you have any question, comment below

DilumN
  • 2,889
  • 6
  • 30
  • 44
  • This is exactly what I wanted—thanks! I have just gone through the process and it worked perfectly. GitHub Desktop doesn't allow cherry-pick so I had to use an alternative client. GitUp and SourceTree both do and I was able to do it in both (I prefer the SourceTree UI fwiw). Thanks again! – Matt Sephton Jan 17 '17 at 18:51
0

You can also use git format-patch and git am pair command to do this.

mkdir patches
git checkout Dev
git format-patch -o patches master

By these three command your patches with one files for one commit will be saved in patches folder.

Then create new branch from master branch and apply all those patches

git checkout master
git checkout -b FEATURE-A
git am patches
gzh
  • 3,507
  • 2
  • 19
  • 23
  • Interesting. I'm not sure I've seen that option in any GUI. Why would you choose format-patch&&am over branches&&cherry-pick? – Matt Sephton Jan 18 '17 at 09:36
  • @MattSephton, Instead of do it one-by-one by cherry-pick, I like to do it in batch mode. – gzh Jan 18 '17 at 09:41
  • I'm not sure I see the batch aspect in your answer above? – Matt Sephton Jan 18 '17 at 11:14
  • @MattSephton, `git format-patch` will create patch files for each commit and save all those to `patches` folder. when you specify `patches` folder to `git am`, git will apply patch files in that folder one by one automatically. – gzh Jan 19 '17 at 02:14
  • great! I'm going to try that next time – Matt Sephton Jan 19 '17 at 09:18