Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull request for just one file [duplicate]

Tags:

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?

like image 936
mankoff Avatar asked Dec 07 '11 19:12

mankoff


People also ask

Can I pull only one file from git?

Short Answergit checkout origin/master -- path/to/file // git checkout <local repo name (default is origin)>/<branch name> -- path/to/file will checkout the particular file from the downloaded changes (origin/master).

How do I clone a single file?

You can't clone a single file using git. Git is a distributed version control system, the Idea behind its clone functionality is to have a complete copy of project and all versions of files related to that project.

How do I only add certain files to a pull request?

Pull requests merge branches. So if you want to isolate some things for a pull request, best is to put those changes in a separate branch. Advantage is that you can change the pull request by pushing new changes to that branch (even push -f if you need to change already pushed commits).

How do I duplicate a pull request?

Marking duplicates To mark an issue or pull request as a duplicate, type "Duplicate of" followed by the issue or pull request number it duplicates in the body of a new comment.


2 Answers

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 
like image 127
Cascabel Avatar answered Sep 26 '22 08:09

Cascabel


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

like image 34
Mat Avatar answered Sep 23 '22 08:09

Mat