Reputation: 181
I know this is not a new question, however I tried many solution provided here and nothing seems to work for me.
I have forked a project to contribute on it. I did multiple commits and they all have been included under one pull request only.
I want to create new pull request for each commit, I tried creating a new branch and cheery-picking particular commit however it doesn't seem to work.
Here is some output from git log --all --oneline --graph --decorate
:
* 340fb9e (origin/click_elements) Feature Request - Click Elements #585
* 8a8f485 (HEAD -> master, origin/new_locator, origin/master, origin/HEAD) Merge remote-tracking branch 'upstream/master'
|\
| * 2466942 (upstream/master) Libdoc updates - link to project and fix 404 (#668)
* | e66862f Added method to find element by class name #673
* | f8ec2ed Feature Request - Click Elements #585
* | 264e38c Added following keywords and their acceptance test cases to fix the issue #463 table_cell_should_not_contain table_column_should_not_contain table_footer_should_not_contain table_header_should_not_contain table_row_should_not_contain table_should_not_contain
| * [truncated: more commits on master in original repo...]
|/
* ef5d24d Merge pull request #539 from ReadmeCritic/master
Someone please let me know how to resolve this issue?
Upvotes: 4
Views: 4170
Reputation: 10227
When submitting a PR on GitHub, it is usually best to keep the PR atomic, and have it up-to-date with the official master
. That is, any branch you are using for a PR should come directly off upstream/master
, and should contain only the commits needed for that PR.
To fix your issue, first, reset master
to be in sync with upstream
:
git checkout master
git reset --hard upstream/master
Now, for each PR you want to submit, create a new branch and cherry-pick the appropriate commit. E.g.:
git checkout -b branch1
git cherry-pick f8ec2ed
git push --set-upstream origin branch1
After you have finished, you can delete your original click_elements
branch:
git branch -D click_elements
git push :click_elements
Or, if you want that branch to only contain the first commit (thus allowing you to reuse the existing PR), do:
git checkout click_elements
git reset --hard 264e38c
git push --force-with-lease
To avoid this problem in the future, never commit directly to master
. Instead, do the following:
Update your repo, if necessary:
git checkout master
git pull upstream master
Create a new branch (git checkout -b mybranch
).
Immediately before submitting your PR, rebase your feature branch:
git checkout master
git pull upstream master
git checkout mybranch
git rebase master
(Depending on the project, you may be able to rebase even after the PR has been opened. However, often you won't need to, especially if you did so right before opening the PR.)
Open the PR.
Obligatory warning: Since a rebase (as well as reset --hard
) rewrites history, this can be dangerous / disruptive for anyone else working on this branch. Be sure you clearly communicate what you have done with anyone you are collaborating with.
Upvotes: 4