简体   繁体   English

Github:从fork中提取一些提交到原始项目中

[英]Github: Pull some commits from fork into original project

I, user1 , have a project at github. 我, user1 ,在github上有一个项目。 Another user2 created a fork and made three commits: A B and C . 另一个user2创建了一个fork并进行了三个提交: A BC

I want to merge only commits A and B back into my project. 我只想将提交AB合并回我的项目中。

How to do it, that I could keep the history in github's network graph? 我该如何将历史记录保留在github的网络图中?

You can add a remote reference to the fork, create a branch on B, and merge that branch (in, for instance, master ): 您可以添加对派生的远程引用,在B上创建一个分支,然后合并该分支(例如,在master ):

git remote add fork /url/of/fork
git fetch --all
git branch tmp fork/B
git checkout master
git merge tmp

I find the merge cleaner than using git cherry-pick . 我发现合并清理器比使用git cherry-pick

The OP Michał Sałaban preferred (in the comments ) create the branch with: OPMichałSałaban首选(在注释中 )创建具有以下内容的分支:

git checkout B 
git branch tmp 

I suggest to use github pull request. 我建议使用github pull request。

GIthub pull request help: https://help.github.com/articles/using-pull-requests GIthub拉取请求帮助: https ://help.github.com/articles/using-pull-requests

How? 怎么样?

simple: 简单:

open a new branch from your current state 从您当前的状态打开一个新分支

git checkout "COMMIT_B_ID"

this will result in detached HEAD 这将导致HEAD脱离

now create a new named branch 现在创建一个新的命名分支

git checkout "MY_B_BRANCH"
git push origin MY_B_BRANCH

now github contains new branch with your changes. 现在github包含您所做更改的新分支。 Go to github and open a pull reauest to merge the new branch with the master 转到github并打开一个pull reauest以将新分支与master合并

This way (Pull requsest) you can see and verfiy that this is exactly what needs to be commited. 通过这种方式(拉取请求),您可以看到并验证这正是需要提交的内容。

Godd Luck. 真幸运。

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

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