Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a pull request for just a single change?

I have almost no clue about git or github and I don't want a clue. But I happen to have a two-line bugfix for an open source project here. In the spirit of cooperation and whatever, I'd like to contribute it back. If it doesn't cost me too much pain.

So, ages ago I forked the repository, then occasionally made a few of my own modifications, and then just recently made this two-line bugfix. Everything has been checked into the master branch and pushed back to origin. Now I want to make a pull request for just the two-line bugfix. It seems github doesn't provide any such facility.

In retrospect, I probably should have made a whole separate project branch before I made my two-line bugfix, but a) that's too much administrative pain for two lines of code and b) I didn't know I'd want to be contributing the bugfix back when I wrote it. And anyway, it's too late now.

I could create a new branch, but that would still contain all the other garbage changes. So it doesn't get me anywhere. I'd like to create a new branch from upstream excluding all my local changes, then redo just this one change. But I can't see any way to do that apart from making a whole new fork, and I don't want a whole new fork.

Right now my best solution is to give up: the code works for me now, it's not my problem. Anyone got a better plan?

like image 468
Matthew Exon Avatar asked Feb 27 '13 08:02

Matthew Exon


1 Answers

The simplest way to do this is to

  1. set a branch with your current changes, and go back on the upstream branch (your commit must be based on the upstream repo)
  2. create a new branch for the pull request
  3. pick up the commit having the bug fix
  4. push and create the pull request

which gives

git branch my-changes
git stash #just in case you have uncommitted changes
git checkout -b bugfix upstream/master
git cherry-pick <bugfix-commit-sha>
git push --set-upstream origin bugfix

where upstream is the original forked repo

like image 162
CharlesB Avatar answered Nov 20 '22 17:11

CharlesB