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 [email protected]: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?

3
  • 1
    No I did the git commit and then, as per the Brew CookBook, git push [email protected]:myname/homebrew.git. Now I want to do a pull request to the upstream repo. Commented Dec 7, 2011 at 19:52
  • @zed_0xff: I don't think so. help.github.com/send-pull-requests Commented Dec 7, 2011 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. Commented Dec 7, 2011 at 19:59

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

4 Comments

Clarified question. I did different commits, but one push.
@mankoff: Then you can start from the point in my instructions where I've created the second commit. I'll leave the rest since it could be useful to others.
where do I do the push in this sequence? When I do it at then end, it says 'Everything up-to-date'.
@mankoff: Then you probably weren't pushing those branches?
10

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

Comments

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>

2 Comments

That's not what he asks.
To tell you the truth, I still can't figure out what is it then…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.