简体   繁体   English

从命令行创建/更新 Git 拉取请求?

[英]Create/Update a Git pull request from command line?

I need to create a git pull-request from the command line, without installing any wrappers or additional software.我需要从命令行创建一个 git pull-request,而无需安装任何包装器或其他软件。 Is there any way to do so in git?有没有办法在git中这样做? I can't seem to find any official git documentation which supports this.我似乎找不到任何支持这一点的官方 git 文档。

Surprisingly (to a lot of people), pull requests are first-class citizens in the git world and not something invented by GitHub.令人惊讶的是(对很多人而言),拉取请求是 git 世界中的一等公民,而不是 GitHub 发明的东西。

Use git request-pull to create an E-Mail text you could send over to someone who should fetch some revisions from a server.使用git request-pull创建一个电子邮件文本,您可以将其发送给应该从服务器获取一些修订的人。

This server could be something very basic like a read-only file share or whatever.该服务器可以是非常基本的东西,例如只读文件共享或其他任何东西。

The topic is discussed in-depth in the Git Book: https://git-scm.com/book/ch5-2.html该主题在 Git Book 中有深入讨论: https : //git-scm.com/book/ch5-2.html

An example: you forked a repo, introduced a patch off the origin/master branch and publish it on a file share called //myserver/myrepo.git .一个例子:你分叉了一个 repo,从origin/master分支引入了一个补丁,并将它发布到一个名为//myserver/myrepo.git的文件共享上。 Then you'd type然后你会输入

git request-pull origin/master //myserver/myrepo.git

Then take the output of the command, paste it into an e-mail and you have your pull-request.然后获取命令的输出,将其粘贴到电子邮件中,然后您就有了拉取请求。

Edit:编辑:

It seems you want a GitHub pull request, not Git pull request.看来您想要一个 GitHub 拉取请求,而不是 Git 拉取请求。 To see the difference, this answer has a good explanation:要查看差异,这个答案有一个很好的解释:

https://stackoverflow.com/a/6235394/245966 https://stackoverflow.com/a/6235394/245966

There is no such a thing as "pull request" in Git itself. Git 本身没有“拉取请求”这样的东西。 The notion of pull requests was introduced to Git ecosystem by the platforms using Git, such as GitHub or Atlassian Stash. 拉取请求的概念是由使用 Git 的平台引入 Git 生态系统的,例如 GitHub 或 Atlassian Stash。

\n

Since it's not a "native" Git concept, you don't have any Git built-ins to open a GitHub pull request from command line. 由于它不是“原生”Git 概念,因此您没有任何 Git 内置程序来从命令行打开 GitHub 拉取请求。

There's a https://github.com/github/hub tool that can help you automate common GitHub flows from command line.有一个https://github.com/github/hub工具可以帮助您从命令行自动化常见的 GitHub 流程。

Having said that, when it comes to opening GitHub pull request or Atlassian Stash pull request, I wrote some command line tools that you can put in PATH to do that job.话虽如此,当涉及到打开 GitHub 拉取请求或 Atlassian Stash 拉取请求时,我编写了一些命令行工具,您可以将它们放在PATH来完成这项工作。 They were written for my specific use case, feel free to modify them to your needs and use them.它们是为我的特定用例编写的,您可以根据自己的需要随意修改它们并使用它们。

For GitHub:对于 GitHub:

For Atlassian Stash:对于 Atlassian Stash:

For them to work, you have to have origin and upstream branches properly configured in your repos.为了让它们工作,您必须在您的存储库中正确配置originupstream分支。 They work in a crude way, by parsing the output of git remote commands to construct proper GitHub/Stash pull request URLs and then open them in the browser.它们以一种粗略的方式工作,通过解析git remote命令的输出来构建正确的 GitHub/Stash 拉取请求 URL,然后在浏览器中打开它们。

The shell scripts are also checking additional stuff, like making sure you open the pull request from proper branch etc. shell 脚本还会检查其他内容,例如确保您从正确的分支打开拉取请求等。

For GitHub, also have a look at对于 GitHub,也看看

which can guess the number of the next pull request and put it in the commit message before you push.它可以猜测下一个拉取请求的编号,并在您推送之前将其放入提交消息中。

Bash Script Bash 脚本

Take a look at the following article which will help you to create PR from the command line.看看下面的 文章,它将帮助您从命令行创建 PR。

Using hub package使用hub

  • Install hub package on your machine.在您的机器上安装hub包。 Follow this link .按照这个链接
  • Checkout to a new branch:结帐到新分支:
     git checkout -b your-branch-name
  • Commit your changes or create an empty commit:提交您的更改或创建一个空提交:
     git commit --allow-empty -m "Your commit message"
  • Push the changes:推送更改:
     git push --set-upstream origin your-branch-name
  • Run the following command to create Pull Request:运行以下命令创建拉取请求:
     hub pull-request

May 2020: you can use the GitHub CLI " gh " 2020 年 5 月:您可以使用GitHub CLI“ gh

See " GitHub CLI allows you to close, reopen, and add metadata to issues and pull requests "请参阅“ GitHub CLI 允许您关闭、重新打开并向问题和拉取请求添加元数据

GitHub CLI 0.8 makes working with pull requests and issues from your terminal even simpler. GitHub CLI 0.8使处理来自终端的拉取请求和问题变得更加简单。 This release includes two primary features:此版本包括两个主要功能:

  • You no longer need to open your issue or pull request in the browser immediately after creating it just to add metadata.您不再需要在创建问题后立即在浏览器中打开您的问题或拉取请求来添加元数据。
    Now you can add reviewers, labels, assignees, projects, and milestones (as applicable) when creating pull requests and issues.现在,您可以在创建拉取请求和议题时添加审阅者、标签、受让人、项目和里程碑(如适用)。
  • Close and reopen pull requests and issues right from the CLI with gh pr close , gh pr reopen , gh issue close , and gh issue reopen .使用gh pr closegh pr reopengh issue closegh issue reopen直接从 CLI 关闭和重新打开拉取请求和问题。

See how to upgrade in our README !在我们的README查看如何升级!

UPD : It looks like it's true and you can't do it "out of the box". UPD :看起来是真的,你不能“开箱即用”。 you'll have to install a wrapper.你必须安装一个包装器。 Check this Can you issue pull requests from the command line on GitHub?检查这个你能从 GitHub 上的命令行发出拉取请求吗? maybe you can find a solution there.也许你可以在那里找到解决方案。

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

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