拉-只要求某些文件/提交

我有一个从 GitHub分支出来的存储库,对它进行了一些修改。但是,在某个提交中,一些文件被更改了,我希望为其提交一个 pull-request,而将其他修改后的文件排除在请求之外。

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

88971 次浏览

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).

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.

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.

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