Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I create a patch that spans commits using Sourcetree?

Martin Gregory August 24, 2012

I observe that when I "Create a patch", the dialog creates the patch that is "to" the commit I selected "from" it's predecessor.


In the dialog, I can tantalisingly select two separate commits and the diff panel shows the diffs that are between those two - that's the patch that I want.


But when I press "OK", I still get the single commit patch.

Is there some way to achieve what I meant.

5 answers

3 votes
Robert Palmer September 3, 2015

I'm seeing the same issue.

Interestingly, if I also select all the files in-between, I get these two DIFFERENT behaviors:

  • If I create ONE patch file, it is ONLY a combination of the first and the last commit
  • If I say create one file per commit, it creates patches for first, last and all in-between, as expected

I have not found a way from SourceTree to create a patch that does this (from the command line):

git diff <1st commit> <2nd commit> > patch.diff

even though the patch panel IS showing what I expect.

What I want: Developer A and Developer B have the same starting point of code.  Developer A does a bunch of work and has made many commits and is now at point X.  Developer A wants to email Developer B a patch file that will get Developer B from their common starting point to point X.

Yes, I could have Developer B clone the git repository, but I'm wanting a patch.  How do I do this?

1 vote
Martin Gregory October 9, 2012

I didn't get to see the content that was removed.

This problem remains for me (I got a reminder from the system asking me if this was resolved or not)

0 votes
dbnex November 13, 2018

Is this still an issue?

I just use SourceTree Tools > Create Patch, then in dialog that opens, select all commits you want to be part of your patch.

David Snape February 18, 2019

I'm using 3.1 on Mac and I have this issue.

0 votes
Martin Gregory September 9, 2013

I accepted Steve's answer to close the question... at least it is supposed to behave the way one would expect ... if I come across the problem again I will re-raise.

Martin Gregory May 28, 2014

Well - I have unaccepted Steve's answer to re-open this question.

The same problem exists, now in 1.9.2.

Appended is a screenshot showing it in action.

On the right is the patch creation dialog. You can see that I have selected two commits that are one commit apart. There are two (only) changes to the file definitions.py, shown in the dialog, and there are also some changes to controller.py.

On the left is the generate patch.diff. You can see that many more files have diffs for them in this patch (at the top) and you can see that more than two changes are being made to definitions.py.

All these extra changes are the changes that led _to_ the earlier of the two selected commits.

The fact that this generation process is fundamentally broken was confirmed when I selected "generate a separate patch file for each commit" in the patch creation dialog. There are only 2 commits between the source and destination that I am chosing, but three patch files were generated when I did this. The first of these contains the same "wrong" deltas - the deltas that led _to_ the earlier selected node.

patch generation problem

marmor007 February 24, 2015

I'm observing the same behavior, the "Create patch..." shows what I want, but the resulting patch is wrong

0 votes
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 24, 2012

When you select 2 lines, it actually shows you the diff *between* these two lines. To be consistent with this, that's the patch that's created, so if these commits are next to each other the difference is actually only the later commit (since the first is the base). Select a wider range to generate a patch for the difference of both commits.

I realise that may not be intuitive, there's a clash here between 'difference between two commits' and 'changes in selected commits'. Since the diff / log always works on the former this sheet also works on that basis.

Martin Gregory August 25, 2012

Actually, this is exactly the behaviour that I was looking for. The display in the diff window is perfect.

Unfortunately, the same patch gets created whether I select one line or two: the "one line" patch.

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 28, 2012

I just tested this, and I could create a patch with the range of commits just fine.

I need to be clear on my point: if you select 2 commits *next to each other*, then the patch created will be just the second commit. That's because a multiple selection is interpreted as "the difference between these two commits". If these commits are next to each other, then the difference between them is just the second commit, because difference is exclusive. For example:

Commit 4
Commit 3
Commit 2
Commit 1

If you select Commit 4 and create a patch, the diff will be Commit 4. If you select Commit 4 and Commit 3, the result will be the same, because the *difference* between them is still only Commit 4. To create a patch including the *changes* in Commit 3 and Commit 4, you have to select Commit 2 and Commit 4, since the difference is 3 and 4. I've tested this here and that's exactly what happens.

As I say, this may not be super-intuitive in the context of creating a patch, but it's consistent with the way multi-selection in the log happens elsewhere (to compare 2 points in history), and consistent with what shows in the diff.

Martin Gregory August 28, 2012

Thanks very much for taking the time to prove to yourself that it works for you, and explain some gotchas.

As I've said, I think the we say that you describe it working makes perfect sense.

Unfortunately, this is not what it does for me. Please see the appended screenshot. You can see that I have selected three rows that end with product version 1.5.3. The diff in the sourcetree window shows what we would expect in the patch file. However, when I right click "create patch" everything looks the same in the "create patch" dialog (indicating we should expet success) but the resulting patch is shown in the editor on the side. You can see that the patch generated is the 1.5.2 Alpha single commit patch: it's the patch of the bottom-most selected row, only, as if the multiselect were not considered. I could also attach the patch-create window, but it looks the same...

Martin

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 31, 2012

Hrm, I can't reproduce this - are you on the latest version of SourceTree (1.5.3)?

Martin Gregory May 28, 2014

I'm now on 1.9.2, and I have the same issue (see below)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events