【问题标题】:Git pull request for just one file [duplicate]仅针对一个文件的Git拉取请求[重复]
【发布时间】:2012-01-15 07:58:43
【问题描述】:

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

我单独提交了更改:

git commit file1
git commit file2

然后我一推到 GitHub:

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

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

【问题讨论】:

  • 不,我做了git commit,然后根据Brew CookBook,git push git@github.com:myname/homebrew.git。现在我想向上游仓库发出拉取请求。
  • @zed_0xff:我不这么认为。 help.github.com/send-pull-requests
  • @halfdan:请先阅读常见问题解答,然后再对此处的主题做出更多断言。 SO的范围包括“程序员常用的软件工具”,这里有近一万两千个Git问题。

标签: git github homebrew pull-request


【解决方案1】:

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

git checkout <rev> -- <file>

【讨论】:

  • 这不是他要的。
  • 说实话,我还是想不通那是什么……
【解决方案2】:

将每个文件放在自己的分支上。您可以为每个分支生成一个拉取请求,它应该可以满足您的需求。

【讨论】:

    【解决方案3】:

    如果您在同一个提交中更改了两个文件,那么不,这是不可能的。推送和拉取操作在提交级别;他们不会把它们分开。

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

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

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

    其中提交A修改了file1,而提交B修改了file2。

    一旦历史看起来像你喜欢的样子,你就可以分别推送两个分支,然后用它们做你需要做的事情:

    git push origin first-branch second-branch
    

    【讨论】:

    • 澄清问题。我做了不同的commits,但是一个push
    • @mankoff:那么您可以从我创建第二次提交的说明开始。剩下的我会留下,因为它可能对其他人有用。
    • 我在哪里按这个顺序推送?当我最后这样做时,它会说“一切都是最新的”。
    • @mankoff:那你可能没有推那些分支?
    猜你喜欢
    • 2012-09-21
    • 2017-08-04
    • 2014-04-30
    • 1970-01-01
    • 2011-12-31
    • 1970-01-01
    • 2019-03-07
    • 2012-03-12
    • 2017-04-11
    相关资源
    最近更新 更多