仅对一个文件的 Git pull 请求

标签 git github homebrew pull-request

<分区>

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

我单独提交了更改:

git commit file1
git commit file2

然后我向 GitHub 推送了一次:

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

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

最佳答案

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

如果您还没有共享更改,您可以将提交分成两个,为每个创建一个分支,然后为它们发起 pull 请求。

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

# 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 A修改了file1,commit B修改了file2。

一旦历史按照您喜欢的方式显示,您就可以分别推送这两个分支并对它们执行您需要执行的操作:

git push origin first-branch second-branch

关于仅对一个文件的 Git pull 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8421552/

相关文章:

python - 如何使用 ZenHub API 设置问题管道

git - 开源项目时处理以前的提交

git - Git 中是否有自动递归克隆的设置?

git - 为什么 git windows 版本在寻址行结尾时的行为与 Linux 版本不同?

Git "push"到 "origin"以外的地方

ruby - 如何列出任何非依赖项的 gem(即,类似于 Homebrew 中的 `brew leaves`)

macos - 在 mac 上安装 OpenCV 3 不会安装 jar

git - "--tree-filter"中的 "--index-filter"和 "git filter-branch"有什么区别?

git - rsync .git 目录

PostgreSQL 错误 'Could not connect to server: No such file or directory'