简体   繁体   English

从Github fork中提取更改

[英]Pull in changes from a Github fork

Someone forked a Github project of mine and made some changes. 有人分叉了我的Github项目并进行了一些更改。 How can I merge the changes back in to my upstream version? 如何将更改合并到我的上游版本中?

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. 我正在寻找的是,是否有办法拉出特定的提交而不是整个分支。

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). 拉入单个提交将是一个挑选,​​并将重写提交ID(并在保留作者时将您标记为提交者)。 The process is pretty straightforward, though: 不过,这个过程非常简单:

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 0920898 you bring the respective commit to your current branch. 使用git cherry-pick 0920898您可以将相应的提交带到当前分支。

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>

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. 如果你将这个命令与你想要抓取的提交的git网页一起使用,你最终会在你的git中提交这个提交。 Even more useful: the commit author is kept and not replaced by you (as it would if you use git rebase ). 更有用:提交作者保留而不是由您替换(如果使用git rebase则会保留)。 If you push this to your repo, the changes will be committed by you , but authored by the original author. 如果您将其推送到您的仓库,则更改将由提交,但由原作者撰写。

A very good ressource on this topic is this guide 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. 它显示了一个很好的工作流程来处理拉取请求,而不是依赖于github上的“恶意”合并拉取请求按钮。

Try to use the /forkqueue on github. 尝试在github上使用/ forkqueue。 There you can merge commits to your fork. 在那里你可以将提交合并到你的分支。

Or go to the tab "Network" and select "Forkqueue" 或者转到“网络”选项卡并选择“Forkqueue”

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

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