git 从 Github 分支中拉取更改

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

Pull in changes from a Github fork

gitgithubgit-mergegit-commit

提问by gregghz

Someone forked a Github project of mine and made some changes. How can I merge the changes back in to my upstream version?

有人分叉了我的 Github 项目并进行了一些更改。如何将更改合并回我的上游版本?

Also, is it possible to pull in just a specific commit?

另外,是否可以只引入一个特定的提交?

What I'm looking is if there is a way to pull a specific commit instead of the entire branch.

我正在寻找的是是否有一种方法可以提取特定的提交而不是整个分支。

回答by Dustin

Pulling in a single commit would be a cherry-pick and would rewrite the commit ID (and mark you as the committer while retaining the author). The process is pretty straightforward, though:

拉入单个提交将是一种选择,并会重写提交 ID(并在保留作者的同时将您标记为提交者)。不过,这个过程非常简单:

git fetch git://github.com/user/project.git
git cherry-pick <SHA-COMMIT-ID>

You get the SHA from the repository log, for example:

您可以从存储库日志中获取 SHA,例如:

git log --oneline

b019cc0 Check whether we have <linux/compiler.h>.
0920898 Include <linux/compiler.h> before including <linux/usbdevice_fs.h>.
cbf0ba1 Add DLT_DBUS, for raw D-Bus messages.
77ed5cd Libnl 2.x returns its own error codes, not errnos; handle that.

With git cherry-pick 0920898you bring the respective commit to your current branch.

随着git cherry-pick 0920898您将相应的提交带到您当前的分支。

回答by frank_neff

Try to use the /forkqueue on github. There you can merge commits to your fork.

尝试使用 github 上的 /forkqueue。在那里你可以将提交合并到你的分支。

Or go to the tab "Network" and select "Forkqueue"

或者转到“网络”选项卡并选择“Forkqueue”

回答by Mr. Anderson

There is an awesome tool which is called hub, which provides useful tools to clean up pull requests and generally "helps you win at git".

有一个很棒的工具叫做hub,它提供了有用的工具来清理拉取请求,并且通常“帮助你在 git 中获胜”。

One useful command in this context is:

在这种情况下,一个有用的命令是:

git am -3 <url>

git am -3 <url>

This allows you to grab the changes from a url and apply its commits/changes to your current local git without even fetching the remote repository (which comes in handy with large repositories).

这允许您从 url 获取更改并将其提交/更改应用于您当前的本地 git,甚至无需获取远程存储库(这对大型存储库非常有用)。

If you use this command with the git webpage of the commit you want to grab, you end up with this commit in your git. Even more useful: the commit author is kept and not replaced by you (as it would if you use git rebase). If you push this to your repo, the changes will be committed by you, but authored by the original author.

如果您将此命令与您想要抓取的提交的 git 网页一起使用,您最终会在您的 git 中得到此提交。更有用的是:提交作者被保留而不被你替换(就像你使用git rebase)。如果您将其推送到您的存储库,更改将由提交,但由原作者创作。

A very good ressource on this topic is thisguide by Nathaniel Talbott. It shows a great workflow to work with pull requests instead of relying on the "malicious" merge pull request button on github.

Nathaniel Talbott 撰写的指南是有关此主题的一个非常好的资源。它展示了一个很好的工作流程来处理拉取请求,而不是依赖 github 上的“恶意”合并拉取请求按钮。