How do I make a patch from a github repo if I failed to make a feature branch?

118 Views Asked by At

I forked/cloned apache whirr on Github, and began work on the trunk branch. During the work, I pulled two commits from origin/trunk. When I generate a patch by running a git diff first_feature_commit HEAD, I get a patch that has these two commits in it. The patch was therefore rejected when I submitted it.

How do I create a patch without the commits that I pulled from origin/trunk?

4

There are 4 best solutions below

0
On

1) Add a remote to the repository you are interested in patching. Probably something like

git remote add upstream https://github.com/apache/whirr.git

2) Fetch the remote. Just get all of them probably:

git fetch --all

3) Make your patch!

git diff upstream/trunk..HEAD >my.patch

HTH! @eldondev

0
On

Generate the patch using git format-patch and it will split them up. You could also just make your diff with git diff HEAD^ to get only your commit (which is presumably the most recent one).

3
On
git checkout -b rj/rilly_feature
git rebase -i master
# remove spurious commits in interactive rebase file
git diff master
# observe success

This is intended to address your "failure" to create a feature branch—if you think you should be working from a feature branch, this will get you on one and allow you to generate a clean patch too.

0
On

When you want to get only those commits that are in your master branch and not on origin/master (the server) you can get those with

git diff origin/master..HEAD

For more details please see Git Tools - Revision Selection of Pro Git.