git 仅对某些文件/提交进行拉取请求

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

Pull-Request for only certain files/commits

gitgithubgit-commitpull-request

提问by Qix - MONICA WAS MISTREATED

I have a repository that is forked from GitHubthat has a few modifications made to it. However, in a certain commit, a few files were changed that I want to submit a pull-request for, leaving the other modified files out of the request.

我有一个从GitHub分叉的存储库,对其进行了一些修改。但是,在某个提交中,更改了一些文件,我想为其提交拉取请求,而将其他修改过的文件排除在请求之外。

Do pull requests merge allcommits, or do I need to do something special to isolate this commit?

拉取请求合并所有提交,还是我需要做一些特殊的事情来隔离这个提交?

采纳答案by CharlesB

A pull request being made of whole commits, you need to split this commit into two separate commits one containing the change to put in the pull request, and the other holding the other changes. To do this you need git rebase -i, see for example How can I split up a Git commit buried in history?for a good explanation on how to do it.

由整个提交组成的拉取请求,您需要将此提交拆分为两个单独的提交,一个包含要放入拉取请求的更改,另一个包含其他更改。为此,您需要git rebase -i,请参阅例如如何拆分埋藏在历史中的 Git 提交?关于如何做到这一点的一个很好的解释。

Once you have split the commit, move the ones you want to include into a topic branch, see for example How to move certain commits to another branch in git?, but it depends if the commits that make your pull request are sequential.

拆分提交后,将要包含的提交移动到主题分支中,例如参见如何将某些提交移动到 git 中的另一个分支?,但这取决于发出拉取请求的提交是否是顺序的。

Then finally you can push to Github and create the pull request from your topic branch.

最后,您可以推送到 Github 并从您的主题分支创建拉取请求。

回答by Ikke

Pull requests merge branches. So if you want to isolate some things for a pull request, best is to put those changes in a separate branch.

拉取请求合并分支。因此,如果您想为拉取请求隔离某些内容,最好将这些更改放在单独的分支中。

Advantage is that you can change the pull request by pushing new changes to that branch (even push -f if you need to change already pushed commits).

优点是您可以通过将新更改推送到该分支来更改拉取请求(如果您需要更改已推送的提交,甚至 push -f)。