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

How to create a patch for a single (or selected) file?

R T
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 21, 2017

I cannot seem to find a way to create a patch (or diff) for a subset of files for a commit.

Environment:

  • Sourcetree 2.6.3 (134) for Mac (OS X Sierra)
  • Git repository on BitBucket

Scenario:

  1. Large commit containing many changes
  2. In History View, I right click on the most recent commit and select "Create Patch..."
  3. Patch window appears.  In the history pane of the patch window I select the version I want to generate the diff (patch) from
  4. In the files window (lower left of the patch window) I select only the files for which I want to view
  5. This works for VIEWING the diffs (it only shows the diffs for the selected files) but when I click "Create" to create the patch file, the patch shows ALL files that have changed

How do I create a patch (diff) file for only the selected files?

2 answers

1 vote
Manju
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 22, 2017

I'm afraid there isn't an option to create patch per file or for individual files in commits. This is possible only if the changes are not committed. 

Feel free to submit an enhancement request on jira.atlassian.com for the Sourcetree team to consider this feature in a future release. 

Thanks,
Manjunath
Sourcetree Mac Developer

Edoardo Molinatti September 12, 2019

Hi Manju, how can it be done if the changes are not committed?
Should the file(s) be staged first?

0 votes
Ni Bu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 13, 2022

As far as I know, this feature is still not implemented in the latest sourcetree version.

But, actually, what you want is possible when creating a patch file from your working copy changes. So there is a workaround by performing the following steps:

  1. You checkout the commit that is one commit ahead of your desired commit
  2. You Cherry Pick your changes from the desired commit (uncheck the check box "Commit immediately upon successful merge". No you have "load" the commit into your working copy.
  3. You click on Actions->Create Patch...
  4. You click on "Working Copy Changes"
  5. You can now select all files that should be included into the patch file

Step 1 may not be needed in every case, but may be helpful to avoid a lot of merge conflicts and to make sure that all changes of the desired commit are included in the patch file.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events