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

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.

4 answers

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?

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)

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.

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.

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.

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

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

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

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.

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

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

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Sourcetree

Tip from the team: configuring Git or Mercurial in Sourcetree

Supported Platforms macOS Windows To make using Sourcetree as simple yet powerful as possible we embed (bundle) dependencies such as Git, Git LFS, and Mercurial. We strive to keep these...

561 views 1 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you