只需一个文件的Git pull请求

时间:2011-12-07 19:48:13

标签: git github homebrew pull-request

我对Git存储库中的两个文件进行了多处更改(具体来说,添加了两个要冲泡的公式)。

我单独提交了更改:

git commit file1
git commit file2

然后我向GitHub推了一次:

git push git@github.com:myname/homebrew.git

我现在想向上游存储库发送两个pull请求,一个用于file1,一个用于file2。这可能吗?

3 个答案:

答案 0 :(得分:10)

如果你在同一次提交中更改了两个文件,那么不,这是不可能的。推送和拉取在提交级别运行;他们不会将他们分开。

如果尚未共享更改,则可以将提交拆分为两个,为每个提交一个分支,然后为这些提交拉取请求。

这是有很多方法可以做的事情之一,但是例如,你可以这样做:

# make sure the commit in question is the most recent
# make branch to point to the previous commit, leaving the changes in your work tree
git reset HEAD^
# commit the changes to the first file
git add file1
git commit
# make a branch for the first commit
git branch first-branch HEAD^
# commit the changes to the second file
git add file2
git commit
# create and check out a branch for this commit
git checkout -b second-branch
# rebase the branch back, so that it doesn't include the first commit
git rebase --onto HEAD^^ HEAD^ second-branch

# point your master branch somewhere that makes sense - maybe before either branch
git checkout master
git reset --hard first-branch^

这会让你留下这样的历史:

- x (master) - A (first-branch)
   \
    - B (second-branch)

其中commit提交修改后的file1,并提交B修改后的file2。

一旦历史看起来如你所愿,你可以分别推动两个分支并做你需要做的事情:

git push origin first-branch second-branch

答案 1 :(得分:9)

将每个文件放在自己的分支上。您可以为每个分支生成一个拉取请求,该请求可以执行您想要的操作。

答案 2 :(得分:1)

您只能获取整个修订版本(实际上是导致修订版的整个分支),但您可以从存储库中访问单个文件:

git checkout <rev> -- <file>