[英]GitHub: How to create pull request from forked repository to upstream repo only including some past commits
I forked a template repository (T) on GitHub and did some work in my own repo (X) making use of the template. 我在GitHub上分叉了一个模板库(T),并在我自己的repo(X)中使用模板做了一些工作。
Now repo X completely conflicts with repo T because of custom work I pushed to X. 现在repo X与repo T完全冲突,因为我推送到X的自定义工作。
Other than doing custom work with the template, I also did some improvements to the template. 除了使用模板进行自定义工作外,我还对模板进行了一些改进。
I created a pull request but it contains all my past commits since forking. 我创建了一个pull请求,但它包含了自forking以来我过去的所有提交。 I want to include only template improvements (just a few commits in the middle of my commit history) in the pull request. 我想在pull请求中仅包含模板改进(在我的提交历史中间只有几个提交)。 How can I achieve this? 我怎样才能做到这一点?
You have to separate the template changes (improvement commits, that you want to merge to the upstream repo with a pull-request ) from your custom commits. 您必须从自定义提交中分离模板更改(改进提交,您要通过pull-request合并到上游存储库 )。
The better way is to use two different git repositories, but in case of you prefer to maintain only one you have to: 更好的方法是使用两个不同的git存储库,但是如果你喜欢只维护一个,你必须:
git checkout -b tempmaster git checkout master # return to the previous one if master
备份你的历史,创建一个新的临时分支git checkout -b tempmaster git checkout master # return to the previous one if master
git remote add upstream https://github.com/ ...
如果您之前没有,请将原始模板存储库(T) git remote add upstream https://github.com/ ...
为上游远程: git remote add upstream https://github.com/ ...
git fetch --all
获取所有远程更改git fetch --all
git reset --hard upstream/master # if master
硬复位当前分支到上游存储库git reset --hard upstream/master # if master
git cherry-pick
) from the temp branch and fix conflicts. 从temp分支导入您的改进提交( git cherry-pick
)并修复冲突。 git checkout -b myapp
and import yours custom commits in the same way. 现在从这个分支你可以创建自己的自定义分支git checkout -b myapp
并以相同的方式导入你的自定义提交。 Once fixed, when you want to update your forked branch (master) with upstream changes, use rebase: git rebase upstream/master
修复后,当您想要使用上游更改更新分叉分支(master)时,请使用rebase: git rebase upstream/master
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.