ChatGPT解决这个技术问题 Extra ChatGPT

你可以从 GitHub 上的命令行发出拉取请求吗?

似乎您必须与 github.com 交互才能发起拉取请求。是这样吗?

我在他们的 API 中看不到任何用于执行拉取请求的内容:develop.github.com
您打算在什么操作系统上执行此操作?
相关:关于 Git(软件)和 GitHub(Web 服务)中 how the pull requests are different 的一些详细信息
在 2020 年 4 月,这将是 gh pr create --fill。请参阅[我在下面编辑的答案](stackoverflow.com/a/60197211/6309

k
kanaka

UPDATEhub 命令现在是官方 github 项目,还支持创建 pull requests

原来的:

添加到集线器命令:http://github.com/defunkt/hub 或 github gem:http://github.com/defunkt/github-gem 似乎特别有用

我建议向那些要求它的项目提出问题。 github的家伙反应灵敏。


github-gem 包含一个为年龄创建拉取请求的工具:gh pull-request [user] [branch]
它是否可以在没有 Github 首先分叉存储库的情况下工作,即从源存储库的直接克隆?
@Holger Just 和其他任何人:这只是创建了拉取请求的文本,并没有绕过对 Github 分叉的需求。我还没有找到解决方法。我打算尽快尝试下面发布的“pullr”实用程序。有关从 github-gem 请求完整拉取请求支持的问题,请参阅 here
对于使用 hub 的快速命令:hub pull-request -m "message pull request" -b master -h your_branch
不知道为什么上面的文档中没有提到它,但是为了快速合并请求,请检查您的主分支hub merge https://github.com/repo/pull/1
m
m_floer

Git 现在附带一个子命令 'git request-pull' [-p] <start> <url> [<end>]

您可以查看文档 here

您可能会发现这很有用,但 it is not exactly the same as GitHub's feature


@NathanBasanese 它生成描述拉取请求的人类可读文本。 git docsGitHub 书说要将其通过电子邮件发送给项目维护者,即对共享存储库(可能是 github)具有写入权限的人。维护者审查您发送的拉取请求文本(而不是使用 github 的在线拉取请求流程)。他们可以对您的拉取请求中指示的 url 和分支执行 git pull,以将您的更改合并到他们的本地克隆中并将这些更改推送到 github。
d
deargle

使用 Hub command-line wrapper,您可以将其链接到 git,然后您可以执行 git pull-request

从集线器的手册页:

   git pull-request [-f] [TITLE|-i ISSUE|ISSUE-URL] [-b BASE] [-h HEAD]
          Opens a pull request on GitHub for the project that the "origin" remote points to. The default head of the pull request is the current branch. Both base and head of the pull request can be explicitly given in one  of  the  following  formats:  "branch",  "owner:branch",
          "owner/repo:branch". This command will abort operation if it detects that the current topic branch has local commits that are not yet pushed to its upstream branch on the remote. To skip this check, use -f.

          If TITLE is omitted, a text editor will open in which title and body of the pull request can be entered in the same manner as git commit message.

          If instead of normal TITLE an issue number is given with -i, the pull request will be attached to an existing GitHub issue. Alternatively, instead of title you can paste a full URL to an issue on GitHub.

不知道 Hub,它可以通过自制软件获得:brew install hub 这似乎是 mac 用户的正确答案。
// , 有没有在线的地方可以让人们了解有关 Hub 的更多信息?
此处提供了有关 hub 命令的更多信息:hub.github.com
n
not2qubit

注意:其中一些答案现在已经过时了。 (2022-01-27)(例如使用 gh Gem。)目前唯一能够做到这一点的工具是 hub 和 gh。

一个男人搜索...

man git | grep pull | grep request

git request-pull <start> <url> [<end>]

但是,尽管有名字,但它不是你想要的。根据文档:

生成一个请求,要求您的上游项目将更改拉入他们的树中。打印到标准输出的请求以分支描述开始,总结了更改并指出可以从哪里提取它们。

@HolgerJust 提到了可以满足您需求的 github gem:

sudo gem install gh 
gh pull-request [user] [branch]

其他人提到了github的官方hub包:

sudo apt-get install hub

或者

brew install hub 

然后

hub pull-request [-focp] [-b <BASE>] [-h <HEAD>]

这会生成待处理更改的摘要,它与通过 Github 发出的拉取请求无关
@Flov 通过“这个”,我假设您的意思是 git request-pull 行。是的,这是有道理的,但我很惊讶 git 没有像 github 那样通过电子邮件发送拉取请求的命令。毕竟,git config user.email 可供它使用。尤其是使用名为 pull-request 的命令。
对于 Ubuntu,看起来 github-cli 在 Precise 之后不再可用...我已经 opened a question 要求提供替代方案。
bitbucket 或 gitlab 呢?来自 CLI 的任何命令?
@GamerAtmos 虽然这不是拉取请求,但它已经接近了。在 GitLab 上,您可以使用普通的 git 客户端创建一个新的私有存储库(项目),其中只有一个 git push -u origin master 和一个新的 origin url。
V
VonC

除了 github/hub,其中 acts as a proxy to Git,您现在(2020 年 2 月)还有 cli/cli

请参阅“Supercharge your command line experience: GitHub CLI is now in beta

创建拉取请求 创建一个分支,进行多次提交以修复问题中描述的错误,并使用 gh 创建拉取请求以分享您的贡献。

https://i.stack.imgur.com/X17nW.png

通过使用 GitHub CLI 创建拉取请求,它还会在您还没有分支时自动创建一个分支,它会推送您的分支并创建您的拉取请求以合并您的更改。

2020 年 4 月:“GitHub CLI now supports autofilling pull requests and custom configuration

GitHub CLI 0.7 已经发布,根据我们的 beta 用户提供的反馈,我们提供了一些要求最高的增强功能。自上一个次要版本 0.6 以来,有三个主要功能: 配置 gh 以使用您的首选编辑器和 gh config set editor [editor]。使用 gh config set git_protocol ssh 将 gh 配置为默认为 SSH。默认的 Git 协议是 HTTPS。使用 gh pr create --fill 从您的提交中自动填充拉取请求的标题和正文。

所以:

gh pr create --fill

我可以在以这种方式提出拉取请求时指定审阅者吗?
@vap 来自 cli.github.com/manual/gh_pr_create,是的,带有选项 -r--reviewer <handle> 请求人员或团队通过他们的句柄进行评论
N
Nishant Nawarkhede

我正在使用简单的别名来创建拉取请求,

alias pr='open -n -a "Google Chrome" --args "https://github.com/user/repo/compare/pre-master...nawarkhede:$(git_current_branch)\?expand\=1"'

这不是创建 PR,而是打开带有 PR 创建页面的浏览器。
s
samccone

我最终自己制作了,我发现它在周围的其他解决方案中效果更好。

https://npmjs.org/package/pullr


尝试在克隆的存储库中执行 pullr -n 。在 Windows 7 上打开 .../clonedRepo/undefined/.pullr-token-cache 时给了我一个错误。您可能想要更多文档 - 例如使用示例?
j
jd_

我最近创建了一个工具,它完全符合您的要求:

https://github.com/jd/git-pull-request

它在单个命令中自动执行所有操作,分叉 repo,推送 PR 等。如果您需要编辑/修复它,它还支持更新 PR!


G
GorvGoyl

您可以安装 github official CLI 来创建 PR 并执行其他类型的 things

建立:

gh auth login

创建公关:

gh pr create

合并:

gh pr merge


如图所示,没有人可以使用这些命令,因为您没有指定操作的存储库或分支。关于如何知道在 auth login 中使用了哪个帐户以及如何确定 PR 是在哪个 repo 中创建的(以及针对哪个帐户)等的更多解释。
这些实际上是完整的命令。您可以在 repo 的根路径运行这些命令,gh 将在内部链接这些命令。对于 gh auth login,系统会询问您是哪个 acc。你想登录..它是交互式的。
A
Andruf

我以前用过这个工具——虽然看起来需要先打开一个问题,但如果你使用 github 问题跟踪,它非常有用并且真正简化了工作流程。 git open-pull 然后从您所在或选择的任何分支提交拉取请求。 https://github.com/jehiah/git-open-pull

编辑:看起来你可以即时创建问题,所以这个工具是一个很好的解决方案。


n
not2qubit

是的。您可以安装 hub CLI 实用程序。
在 MACOS 上:brew install hub

您需要拥有一次 GitHub 令牌才能登录。

User -> Dev settings -> Personal tokens -> Generate
(参见:https://github.com/settings/tokens

git checkout -b mybranch
hub pull-request -b master -h mybranch

#user:     your_user_name
#password: your_git_token