git 如何从分叉回购更新拉取请求?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9790448/
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 13:15:13  来源:igfitidea点击:

How to update a pull request from forked repo?

gitversion-controlgithub

提问by stevebot

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.

所以我首先分叉了一个 repo,然后对那个分叉的 repo 进行了提交。然后我打开了一个拉取请求。拉取请求列出了我想要的所有更改。

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 中进行了这些更改,现在如何使用这些更改更新拉取请求(或者这不是我应该处理的方式)?

采纳答案by shelhamer

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
  1. 打开拉取请求
  2. 根据本地存储库中的反馈提交更改
  3. 推送到你的叉子的相关分支

The pull request will automatically add the new commits at the bottom of the pull request discussion (ie, it's already there, scroll down!)

拉取请求将自动在拉取请求讨论的底部添加新的提交(即,它已经存在,向下滚动!

回答by jmu

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 中更新拉取请求就像将想要的更改提交到现有分支(与拉取请求一起使用)一样简单,但通常也希望将更改压缩为单个提交:

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.

...现在拉取请求只包含一个提交。



Related links about rebasing:

关于 rebase 的相关链接:

回答by igorw

Just push to the branch that the pull request references. As long as the pull request is still open, it should get updated with any added commits automatically.

只需推送到拉取请求引用的分支。只要拉取请求仍处于打开状态,它就会自动更新任何添加的提交。

回答by Vikasdeep Singh

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>
  1. git reset --hard <commit key of the pull request>
  2. 是否对我想做的代码进行了更改
  3. git add
  4. git commit --amend
  5. git push -f origin <name of the remote branch of pull request>

回答by AaronLS

If using GitHub on Windows:

如果在 Windows 上使用GitHub

  1. Make changes locally.
  2. Open GitHub, switch to local repositories, double click repository.
  3. Switch the branch(near top of window) to the branch that you created the pull request from(i.e. the branch on your fork side of the compare)
  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.
  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. 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).
  1. 在本地进行更改。
  2. 打开GitHub,切换到本地仓库,双击仓库。
  3. 将分支(靠近窗口顶部)切换到您从中创建拉取请求的分支(即比较叉侧的分支)
  4. 应该看到在右侧输入提交评论并将更改提交到本地存储库的选项。
  5. 单击顶部的同步,其中包括将您的提交从本地推送到 GitHub 上的远程分支。
  6. 拉取请求将随着额外的提交自动更新。这是因为拉取的请求与您的分支分支存在差异。如果您转到拉取请求页面(您和其他人可以对您的拉取请求发表评论的页面),那么“提交”选项卡应该包含您的其他提交。

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.

这就是为什么在开始自己进行更改之前,您应该为计划放入拉取请求的每组更改创建一个分支。这样,一旦您发出拉取请求,您就可以创建另一个分支并继续处理其他一些任务/功能/错误修复,而不会影响之前的拉取请求。