Title: github question on contributing to bitcoin - unsure about creating a PR Post by: Kogs on March 22, 2018, 08:22:06 AM I was missing a small, let's say feature, in the current bitcoin-qt version. So I decided to implement this by myself.
As I never contributed to an OSS before I did some research on how to do that correctly. Starting point was the CONTRIBUTION document from the bitcoin repository https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md (https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md). My missing knowledge there was basically the correct use of git / github with branches, remote repositories, merging and pull requests. I learned about that and I'm quite confident that I understood all those stuff. I already did
Now comes the part where I'm uncertain if I did everything correct or if I'm missing something. On github I browsed to my bitcoin fork, selected my pushed topic branch and clicked the "New Pull request" button. There I see the comparison from bitcoin/bitcoin to my_fork/topic_branch. The suggested title for the pull request by github is my last commit message from my topic branch. So far so good. But I expected to see only my changes I made within the topic branch, but additionally I also see all the changes from my previously pull requests from bitcoin/bitcoin which I merged to my master branch. Of course I don't want to have those changes in my pull request back to bitcoin/bitcoin. I did not see anything on github which allow me to select only my last commit to be in the pull request. What did I miss or how can I create a pull request with only the changes done in the topic branch and not everything I have done in the master branch? I would appreciate any hints on how to solve this issue. Thank you in advance. Title: Re: github question on contributing to bitcoin - unsure about creating a PR Post by: starmyc on March 22, 2018, 08:30:30 AM What did I miss or how can I create a pull request with only the changes done in the topic branch and not everything I have done in the master branch? When you do a pull request, it will ask for the upstream project to pull the whole branch contents & do a diff against upstream branch. This includes your commits in the current branch, but also all commits that are in the history in the branch. So, if history on upstream is A -> B -> C, you clone this, then create a feature D you push in master in your own repository, then create a branch from D and commit E (you'll get A -> B -> C -> D -> E in this branch), the pull request will make a diff between upstream history (A -> B -> C) and your current commit log (A -> B -> C -> D -> E), and not only the commits you exclusively made in your branch. What you want to do is clone the upstream repository and commit your new feature by creating a branch from upstream's master branch, not from your master branch. Edit: To be more specific (sorry, I had to go AFK): Code: $ git remote -v Title: Re: github question on contributing to bitcoin - unsure about creating a PR Post by: Kogs on March 22, 2018, 09:43:35 AM What did I miss or how can I create a pull request with only the changes done in the topic branch and not everything I have done in the master branch? When you do a pull request, it will ask for the upstream project to pull the whole branch contents & do a diff against upstream branch. This includes your commits in the current branch, but also all commits that are in the history in the branch. So, if history on upstream is A -> B -> C, you clone this, then create a feature D you push in master in your own repository, then create a branch from D and commit E (you'll get A -> B -> C -> D -> E in this branch), the pull request will make a diff between upstream history (A -> B -> C) and your current commit log (A -> B -> C -> D -> E), and not only the commits you exclusively made in your branch. What you want to do is clone the upstream repository and commit your new feature by creating a branch from upstream's master branch, not from your master branch. Thank you for your quick response. I had to lookup what an upstream repository is, but I think I found out how it works. I did the following $ git remote add upstream https://github.com/bitcoin/bitcoin $ git fetch upstream getting the last changes from upstream to be up to date $ git checkout master $ git merge upstream/master then I checked out the upstream/master $ git checkout upstream/master $ git checkout -b <topic_branch> and added my changes again. Unfortunately the last update killed my changes as the feature I wanted to add relies on a feature which was removed 2 days ago.... So I cannot continue to check if creating a pull request would work the way I did now. Maybe you can tell me if I'm on the right track with my steps above so I can do it correctly when I have another change I want to contribute? What would be the correct next steps to create a pull request? $ git commit $ git push -u upstream/master <topic_branch> Would I see then the upstream branch in my github repository to be able to create the pull request from there? I think I need to do some experimenting on a github test project as well to see how everything works. Edit: did not see your last edit before posting my comment. But it looks like I found the correct way how to do it. I think I just did also some unnecessary steps. I will do some tests on a test project to make sure I understood everything correctly. Thank you so much! Title: Re: github question on contributing to bitcoin - unsure about creating a PR Post by: starmyc on March 22, 2018, 09:57:40 AM then I checked out the upstream/master $ git checkout upstream/master $ git checkout -b <topic_branch> and added my changes again. That's the same thing, and you got it right ! Unfortunately the last update killed my changes as the feature I wanted to add relies on a feature which was removed 2 days ago.... So I cannot continue to check if creating a pull request would work the way I did now. Sorry for that... that is life of opensource :) Maybe you can tell me if I'm on the right track with my steps above so I can do it correctly when I have another change I want to contribute? What would be the correct next steps to create a pull request? $ git commit $ git push -u upstream/master <topic_branch> Would I see then the upstream branch in my github repository to be able to create the pull request from there? No, you can't push on upstream, you don't have the permissions to do it so. You just push your branch to your github repository, doing git push origin, and create a PR (you'll get a beautiful "Compare & pull request" showing on your fork repository page on github) Code: $ git push origin Title: Re: github question on contributing to bitcoin - unsure about creating a PR Post by: Kogs on March 22, 2018, 11:29:32 AM No, you can't push on upstream, you don't have the permissions to do it so. You just push your branch to your github repository, doing git push origin, and create a PR (you'll get a beautiful "Compare & pull request" showing on your fork repository page on github) Code: $ git push origin Got you. Thanks |