如何在没有合并提交或使用CLI的情况下保持GitHub的最新状态?

bre*_*ine 15 github github-for-windows github-desktop

有助于回购的普通GitHub流程是创建上游的分支,在您进行更改的地方克隆本地副本,然后将其推回分支,然后创建PR以将您的更改合并到上游。

但是,如果此后上游发生了变化,那么如何在不创建合并提交的情况下(也无需使用git CLI)更新fork?

我已经知道如何以创建合并提交或依赖git命令行界面的方式执行此操作。该问题专门用于仅使用GitHub.com网站或GitHub桌面应用程序(无CLI)。

由于这是一个非常常见的工作流程,因此似乎应该有一些使用GitHub GUI进行操作的简单方法。

To reiterate: any answers that use the CLI or create a merge commit (e.g. this way) will not be answering this question since I'm explicitly looking for a non-CLI solution.

Von*_*onC 11

没有合并提交或使用CLI?

不直接与单独GitHub的网页界面,因为这将涉及基础重建之上你的PR分支upstream/master

简而言之:不。
但短话短说...也许,如果您真的想尝试一下。

自2016年9月以来,实际上可以通过GitHub Web UI进行基础调整,...

  • 如果您是原始存储库的维护者,想要集成PR分支
  • 如果重播的提交均未引发冲突

https://github.blog/wp-content/uploads/2016/09/a03fa9b6-7f35-11e6-8fa0-e16b2fede8ca.gif?resize=788%2C423

(This differs from GitHub Desktop, which, since June 5th 2019 does support rebasing. But that is a frontend to Git CLI, like other tools provide. For example GitKraken and interactive rebase)

So a convoluted workaround would be:

  • to fetch, then push upstream/master to the master branch of your own fork (a CLI operation, but more on that below)
  • change the base branch of your current PR to master (so a PR within the same repository: your own fork), provided you haven't pushed to master.
    Meaning: master in your fork represents the updated upstream/master, with upstream being the original repository that you have forked.
  • Since you are the owner of that repository (your fork), GitHub can then show you if you can rebase said branch to the base branch of the PR (master), but only if there is no conflict.
  • finally, change the base branch again, to <originalRepo>/master (which is the intended target of your PR)

The very first step is typically done through command line, but... there might be a trick to do it (update upstream master in your fork) through web UI: see "Quick Tip: Sync a Fork with the Original via GitHub’s Web UI" by Bruno Skvorc

In short, it involves:

  • creating a new branch from your current master (which would be at upstream/master at the time you forked the original repository)

https://help.github.com/assets/images/help/branch/branch-creation-text-box.png

  • Making a PR with that new branch and <originalRepo/master>
  • doing a base switch before creating the PR

https://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2016/02/1454845571Screenshot-2016-02-07-12.41.28-1024x411.png

https://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2016/02/1454964017Screenshot-2016-02-07-12.41.42.png

That is the step which artificially forces upstream/master to be refreshed

You can the create and merge it with the “Merge Pull Request” button (and “Confirm Merge” afterwards): the merge will be trivial: no merge commit.

The end result is: your own master branch (in your fork) updated with upstream/master (the master branch of the original repository)!

You can then resume the steps I describe above, and change the base of your current PR to your own (now refreshed) master branch, and see if you can rebase it!


Sia*_*vas 6

考虑到以下因素,从1.0.7版本开始,这对于GitHub Desktop是可行的:

  • 如果当前分支在上游没有任何提交(派生的原始回购),则可以在不创建新合并提交的情况下提取新提交

    在GitHub桌面中:

    1. 从克隆您的存储库 File > Clone Repository

    2. Fetch origin,这也会自动获取上游

    3. Branches点击它说:Current Branch

    4. 点击Choose a branch to merge into <branch>底部

    5. 搜索upstream/<branch>,然后单击Merge upstream/<branch> into <branch>

    6. 推到起源,等等!

  • 否则,如果当前分支已经在派生分支之前提交了,那么当然必须创建一个合并提交或重新设置并强制推送。若要进行更佳的变基,请执行以下操作:

    1. 在GItHub Desktop中,Branch从菜单转到,然后Rebase Current Branch

    2. 搜索upstream/<branch>,然后单击Start Rebase

    3. 解决基准库中发生的任何冲突

    4. 强制推到原点。出于明显的原因,您将因此得到警告。

为了避免在当前分支位于上游分支的前面和后面时强行推动工作,请创建新的合并提交或:

  • 根据您的所有更改创建新分支

  • 如果需要,将原始分支重置为原始状态(在与原始仓库分离之前)

  • 从第一种情况开始执行步骤,并将您的更改合并到分支中。

是的,这似乎是通过从原来的回购GitHub的网站拉,而无需创建一个拉请求和合并提交不是可以在这一刻。


第一种情况的演示GIF:https//imgur.com/a/8wci2yf

与此相关的一些GitHub问题:


pra*_*hal 5

更新 说明:基于非 CLI 的方法可能会有所帮助: Is there a way to make GitHub Desktop rebase abranch against master?

这里唯一的关键是进行变基,所以上面的答案应该有帮助。


CLI方式(比较容易使用git,所以默认应该更全面)

您应该使用一些做法来避免这种情况。

  • 不要在你的分支中的 master 分支上工作。
$ git clone <your fork>
$ git checkout -b feature_branch
Run Code Online (Sandbox Code Playgroud)

您可以先进行工作feature_branch,然后提出 Pull 请求。

  • 一旦您的更改合并到上游主版本中,您就可以从上游拉取到您的源。由于上游的 master 会将您的提交整齐地放在其之上,因此不会有合并提交。
$ git checkout master
$ git pull upstream master
$ git push origin master
Run Code Online (Sandbox Code Playgroud)
  • 在这种情况下,维护者与您的分叉中的主版本不同,也就是说,它不再是线性的,您需要提取它的新副本。这应该不是问题,因为您的更改已经在上游。

  • 如果你在做 PR 的时候上游的 master 已经进步了,那么你就可以 rebase 了feature_branch

$ git checkout master
$ git pull upstream master
$ git push origin master
$ git checkout feature_branch
$ git rebase master
Run Code Online (Sandbox Code Playgroud)

详细参考此文档:Fork and Pull Request 工作流程

  • CLI 是指命令行界面。因此,答案中所有以“$”开头的行都是 CLI。我试图让我的问题非常清楚,我并不是在寻找 CLI 解决方案。您能否给我一些建议,告诉我如何使我的问题更清楚,因为我不是在寻找 CLI 解决方案? (2认同)