简体   繁体   English

如何从forked repo更新pull请求?

[英]How to update a pull request from forked repo?

So I first forked a repo and then made a commit to that forked repo. 所以我首先分叉了一个回购,然后提交了一个分叉的回购。 I then opened a pull request. 然后我打开了拉取请求。 The pull request listed all the changes I wanted. pull请求列出了我想要的所有更改。

After reviewing my pull request, there were a number of changes that the repo owner wanted me to make before he accepted it. 在审核了我的拉取请求之后,回购所有者希望我在接受之前做出一些更改。 I have made those changes in my fork, now how do I update the pull request with those changes (or is this not how I should handle it)? 我已经在我的fork中进行了这些更改,现在如何使用这些更改更新pull请求(或者这不是我应该如何处理它)?

You have done it correctly. 你做得对了。 The pull request will automatically update. 拉取请求将自动更新。 The process is: 过程是:

  1. Open pull request 开拉请求
  2. Commit changes based on feedback in your local repo 根据您当地仓库中的反馈提交更改
  3. Push to the relevant branch of your fork 推送到fork的相关分支

The pull request will automatically add the new commits at the bottom of the pull request discussion (ie, it's already there, scroll down! ) pull请求将自动在pull请求讨论的底部添加新提交(即, 它已经存在,向下滚动!

Updating a pull request in GitHub is as easy as committing the wanted changes into existing branch (that was used with pull request), but often it is also wanted to squash the changes into single commit: 在GitHub中更新pull请求就像将所需的更改提交到现有分支(与pull请求一起使用)一样简单,但通常也需要将更改压缩到单个提交中:

git checkout yourbranch
git rebase -i origin/master

# Edit command names accordingly
  pick   1fc6c95 My pull request
  squash 6b2481b Hack hack - will be discarded
  squash dd1475d Also discarded

git push -f origin yourbranch

...and now the pull request contains only one commit. ...现在,pull请求只包含一个提交。


Related links about rebasing: 关于变基的相关链接:

Just push to the branch that the pull request references. 只需按下pull请求引用的分支即可。 As long as the pull request is still open, it should get updated with any added commits automatically. 只要拉取请求仍然打开,它应该自动更新任何添加的提交。

I did it using below steps: 我用以下步骤做到了:

  1. git reset --hard <commit key of the pull request>
  2. Did my changes in code I wanted to do 我的代码改变了吗?
  3. git add
  4. git commit --amend
  5. git push -f origin <name of the remote branch of pull request>

If using GitHub on Windows : 如果在Windows上使用GitHub

  1. Make changes locally. 在本地进行更改。
  2. Open GitHub, switch to local repositories, double click repository. 打开GitHub,切换到本地存储库,双击存储库。
  3. Switch the branch(near top of window) to the branch that you created the pull request from(ie the branch on your fork side of the compare) 将分支(靠近窗口顶部)切换到您从中创建拉取请求的分支(即比较的fork侧的分支)
  4. Should see option to enter commit comment on right and commit changes to your local repo. 应该看到右边输入提交注释的选项,并提交对本地仓库的更改。
  5. Click sync on top, which among other things, pushes your commit from local to your remote fork on GitHub. 单击顶部的同步,除其他外,将您的提交从本地推送到GitHub上的远程分支。
  6. The pull request will be updated automatically with the additional commits. 拉取请求将通过附加提交自动更新。 This is because the pulled request represents a diff with your fork's branch. 这是因为pull请求表示fork分支的diff。 If you go to the pull request page(the one where you and others can comment on your pull request) then the Commits tab should have your additional commit(s). 如果您转到拉取请求页面(您和其他人可以对您的拉取请求发表评论的页面),则“提交”选项卡应该包含您的其他提交。

This is why, before you start making changes of your own, that you should create a branch for each set of changes you plan to put into a pull request. 这就是为什么在开始更改自己的更改之前,应该为计划放入拉取请求的每组更改创建一个分支。 That way, once you make the pull request, you can then make another branch and continue work on some other task/feature/bugfix without affecting the previous pull request. 这样,一旦你发出了拉取请求,你就可以创建另一个分支并继续处理其他任务/功能/ bug修复,而不会影响之前的拉取请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM