git 如何修改 Github 拉取请求?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16748115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:14:02  来源:igfitidea点击:

How to modify Github pull request?

gitgithubpull-request

提问by flygoast

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?

我该怎么做?我是否应该保持提交哈希不变,我该怎么做?

回答by Daij-Djan

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

如果你想让 b 合并到 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
  1. 你把 c1,c2,c3 推到 b
  2. 然后你对 b 提出一个新的请求
  3. 它被,你需要更多的提交
  4. 你把 c11,c21,c31 推到 b
  5. 拉取请求现在显示所有 6 次提交

回答by Malvineous

I just had one commit in a pull request, and I used git commit --amendto update it. I then did a force push with git push -fso 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.)

我在拉取请求中只有一次提交,我曾经git commit --amend更新过它。然后我做了一个强制推送,git push -f所以我修改后的提交替换了原来的提交。拉取请求会自动获取新的提交。(它实际上显示了两个提交,但是当我重新加载页面时,旧的提交已经消失了。)

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.

因此,虽然通常不推荐强制推送,但它对于拉取请求很有用。不推荐这样做,因为如果有人在你的基础上提交了一个提交,那么他们将不得不在你的更改之后进行 rebase。但是由于没有人应该将他们的工作建立在中的拉取请求上,因此在这种情况下应该是非常安全的。

回答by user_19

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.
  1. 通过执行以下操作,从存储库(上游)和分支(开发)创建一个新分支(修复),您打算将拉取请求发送到该分支:

    git 分支修复上游/开发

  2. 将您的精炼提交直接添加到这个新创建的分支。

    git commit -m "你的消息"

  3. 将此分支推送到您自己的分叉远程(可以命名为 origin)。

  4. 比较并发送具有干净提交历史的新拉取请求。
  5. 此外,最好在合并拉取请求后删除您的分支。
  6. 您可以评论并关闭您之前的拉取请求。

回答by hexaJer

You also can use github api.

您也可以使用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

您可以在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