How to modify GitHub pull request?

GitGithubPull Request

Git Problem Overview


I've opened a pull request to a project. The maintainer has decided to accept it, but told me to modify some contents.

How can I do it? Whether I should keep the commit hash unchanged, how can I do it?

Git Solutions


Solution 1 - Git

Just push more commits on to the branch the request is for. The pull request will pick this up then.

Example:

If you want to have b merged into master

  1. You push c1,c2,c3 to b
  2. then you make a new request for b
  3. it gets reviewed and you need more commits
  4. You push c11,c21,c31 to b
  5. The pull request now shows all 6 six commits

Solution 2 - Git

I just had one commit in a pull request, and I used git commit --amend to update it. I then did a force push with git push -f so my amended commit replaced the original one. The pull request automatically picked up the new commit. (It actually showed both commits, but when I reloaded the page the old commit had gone.)

So while a forced push is generally not recommended, it can be useful for pull requests. It's not recommended because if someone bases a commit on top of yours then they will have to do a rebase after your change. But since nobody should be basing their work on an under-review pull request, it should be pretty safe in this situation.

Solution 3 - Git

If you continue to make changes and keep pushing to the same branch, the refined commits will be added to the same pull request (unless your pull request has been merged). This could make the history very cluttered.

An alternate solution and a technique that I use is as follows:

  1. Create a new branch (fixes) from the repository(upstream) and branch (develop) to which you intend to send the pull request by doing:

    git branch fixes upstream/develop

  2. Add your refined commits directly to this newly created branch.

    git commit -m "your message"

  3. Push this branch to your own forked remote (could be named origin).

  4. Compare and send in a new pull request with clean commit history.

  5. Also, it is a good idea to delete your branch after the pull request has been merged.

  6. And you can comment and close your earlier pull requests.

Solution 4 - Git

You also can use github api.

example with curl
curl --user "your_github_username" \
     --request PATCH \
     --data '{"title":"newtitle","body":"newbody",...}' \
     https://api.github.com/repos/:owner/:repo/pulls/:number

you can find the detailled list of data in github developer doc

example : change name of my pull request
curl --user "jeremyclement" \
     --request PATCH \
     --data '{"title":"allows the control of files and folders permissions."}' \
     https://api.github.com/repos/Gregwar/Cache/pulls/9

Solution 5 - Git

Apply your changes over top of your existing branch where the PR is created. For example if you branch name is newFeature and you have create PR to merge newFeature into develop branch. Apply the suggested changes on the newFeature branch with as many commits you want. Once you are completed with fixing suggested review changes. Allow the reviewer to re-review it. Once approved you should be able to merge your PR.

You can use SourceTree or some GUI tool if you need help in general with git.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionflygoastView Question on Stackoverflow
Solution 1 - GitDaij-DjanView Answer on Stackoverflow
Solution 2 - GitMalvineousView Answer on Stackoverflow
Solution 3 - Gituser_19View Answer on Stackoverflow
Solution 4 - GithexaJerView Answer on Stackoverflow
Solution 5 - GitMaxView Answer on Stackoverflow