Redemption of Atlassian Answers T-Shirts, Backpacks and Jackets is temporarily unavailable while we migrate to a new third-party provider for https://swag.atlassian.com.

Sometimes when committing to a local repository a large group of changes may be applied within a commit. (I find that this happens more often when working on the console, or in a VM someplace, away from SourceTree) Later on, when I pull such changes to SourceTree from the remote, I want to prepare them for pushing upstream (where I have no write access) as patches.

Unfortunately, right now I cannot see how to achieve this.

When selecting a historic commit with multiple hunks in the same file that I wish to produce separate patches for, selecting Actions | Create Patch I am presented with two options, either:

  1. Patch from Working Copy (not the desired route); or
  2. Patch from Commits

The second option presents the file in question and each of the multiple hunks, however there is no means to select one or a subset of hunks (as I seem to remember is well implemented via the cherry pick interface elsewhere within SourceTree) to use as the basis for patch generation.

Instead, I am only given the option to Reverse the entire set of changes within the file (apparently on the working tree?) or Reverse Hunk for each hunk within the file (again, apparently on the working tree).

What I really want to do is to produce a patch from one or more hunks the have changed within one file (but ideally the option of more) within a single commit (but ideally the option of more, between arbitrary points in time).

Because the individual hunks already perfectly represent the logical objects from which patch generation is desired, it seems extremely counter-intuitive that there appears to be no way to do this.

Perhaps I am missing something?

    CommentAdd your comment...

    1 answer


      Hi Walter,

      This is something that's been requested, basically to create a patch from hunks in a file by using the diff pane. The problem is that the patch command doesn't allow for hunks, it's an all-or-nothing command. Of course we could stash away changes, apply hunks, create the patch and revert back to your previous state, but we don't mess around with files like that ever because we could lose your changes - so we rely on what Git/Hg allow us to do within the bounds of never harming your files.

      For more info in Git, checkout the git-diff page and the git-format-patch page. For Hg, take a look at the diff doc to see available options. You'll see there's no way to specify hunks or lines or anything of the sort to create a patch with. So the answer is that unfortunately it's a limiation of Git/Hg. If some safe viable solution were to come up in the future we'd be more than happy to adopt it (it's something I'd love myself!).

      Hope that helps

      1. Walter Stanish
        OK. Safe viable solution thinking cap on. Would it not be possible to avoid the danger-to-files issue by copying files outside of git/hg and performing the hunk-based diffs in that (safe) space? Obviously there is demand here ... SourceTree's major value-add is UI ... I don't think there's a need to stick to what's available in the underlying toolsets if there's demand and safe routes to achieve the desired outcomes.
      CommentAdd your comment...