25

I've made multiple changes to two files in a Git repository (specifically, added two formulae to brew).

I committed the changes individually:

git commit file1
git commit file2

I then did one push to GitHub:

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

I'd now like to send two pull requests to the upstream repository, one for file1, one for file2. Is this possible?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mankoff
  • 2,225
  • 6
  • 25
  • 42
  • 1
    No I did the `git commit` and then, as per the Brew CookBook, `git push git@github.com:myname/homebrew.git`. Now I want to do a pull request to the upstream repo. – mankoff Dec 07 '11 at 19:52
  • @zed_0xff: I don't think so. http://help.github.com/send-pull-requests/ – Cascabel Dec 07 '11 at 19:52
  • 10
    @halfdan: Please go read the FAQ before you make any more assertions about what's on topic here. The scope of SO includes "software tools commonly used by programmers", and there are nearly twelve thousand Git questions here. – Cascabel Dec 07 '11 at 19:59

3 Answers3

10

Put each file on its own branch. You can generate a pull request for each branch, which should do what you want.

Mat
  • 202,337
  • 40
  • 393
  • 406
10

If you changed both files in the same commit, then no, this isn't possible. Pushes and pulls operate at a commit level; they won't split them apart.

If you haven't shared the changes yet, you could split the commit into two, making a branch for each, and then initiate pull requests for those.

This is one of those things there are many ways to do, but for example, you could do something like this:

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

This would leave you with history like this:

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

where commit A modified file1, and commit B modified file2.

Once the history looks the way you like it, you can push the two branches separately and do what you need to do with them:

git push origin first-branch second-branch
Cascabel
  • 479,068
  • 72
  • 370
  • 318
3

You can only fetch the whole revision (actually, the whole branch leading to the revision), but you can then access individual files from your repository:

git checkout <rev> -- <file>
Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173