It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

"This is not a valid patch file." for a patch file that I *just* created.

No matter what I do, it says:

This is not a valid patch file.

I just created a patch file from either a working copy or a commit using Create Patch yet it says that. I used to use patch files all the time for several years this way but now I can never get the Apply Patch to work.

10 answers

So it turns out that it's not a bug but a feature(!). When it's not working copy, Sourcetree appends more info to the patch file (then it's not a patch file anymore...) so when I remove those information, the patch works fine.

For instance, here is the patch file Sourcetree creates from an old commit:

From 24e5d114c5809c3cad52f1c2ef693fa07b84cb7e Mon Sep 17 00:00:00 2001
From: Kubilay Erdogan <>
Date: Thu, 21 Feb 2019 15:42:23 +0100
Subject: [PATCH] Add todo.

---
project/Class.swift | 1 +
1 files changed, 1 insertions(+)

diff --git a/project/Class.swift b/project/Class.swift
index 00806946..742f52ef 100644
--- a/project/Class.swift
+++ b/project/Class.swift
@@ -335,6 +335,7 @@ extension Class {
case foo

// New definitions
+ // TODO: Create documentation for these

case bar

--
2.18.0

And I get "This is not a valid patch file" error when I try to apply the patch.

But if I remove the header and footer info (Text before the first `diff` and the last two lines (double dashes and version info(?)) then it works.

So the working patch file is:

diff --git a/project/Class.swift b/project/Class.swift
index 00806946..742f52ef 100644
--- a/project/Class.swift
+++ b/project/Class.swift
@@ -335,6 +335,7 @@ extension Class {
case foo

// New definitions
+ // TODO: Create documentation for these

case bar

Hope this helps someone.

You just saved me a full days work. Thank you!

Like Kubilay Erdogan likes this

You are the best! 

I'm having the same issue. 

 

macOS Mojave(10.14.2)

 

SourceTree v 3.0.1 (205)

Like Emre Serbetcioglu likes this

Same here. Patch created by SourceTree can be applied in console with "git apply".

Like David Corrie likes this

I had the same issue on MacOS 10.14.2 and SourceTree 3.0.1 (205).

 

I downloaded SourceTree 3.0.0 (300) and the same issue was present there as well.

 

I downloaded SourceTree 2.7.4 (175) and the patch functionality worked fine. Patches generated by 2.7.4 and even patches generated by 3.0.0 were applied correctly. This would imply that the message "This is not a valid patch file" is actually incorrect and the bug is in the patch file parser, not the patch file generator. Hope this helps.

Does anyone know how to get SourceTree's attention on this bug?

0 votes
bgannin Atlassian Team Dec 18, 2018

Hi Christopher,

What version of Sourcetree are you using? What platform are you on? 

Brian Ganninger
Senior Mac Developer, Sourcetree

I am having the same issue. Version:

MacOS

3.0.1 (205)

Same problem here too.  I had to roll back to 2.x to get patching to work.

I also get this issue. I create a patch file the usual way through sourcetree but I can't apply it.

Mac OS

3.0.1 (205)

I have the exact same issue. 

Mac OS

3.0.1 (205)

The same thing for me.

MacOS

v3.0.1 (205)

I have the same issue. MacOS 10.13.3 and SourceTree 3.0.1 (205)

Same issue. Mojave, ST 3.0.1 (205)

Quite surprised that this has been going on for a while. I will try to downgrade to a version that actually works. Such a shame.

I had the same issue on 3.1, downgraded to 2.7.4, and it is working fine. Seems to be a bug in the patch parser.

Same issue in 3.0.1...

MacOS Mojave 10.14.3

Broken here as well, SourceTree 3.1.0, on macOS 10.14 (18A391), Darwin 18.0.0 kernel.

Same issue - SourceTree 3.1 (210)

Same here, SourceTree 3.1.1 (213) on macOS 10.14.4 Mojave using embedded Git 2.20.1. Switching over to System git (2.21.1) does not help.

If you remove the header from the patch file (e.g. the part up to the first diff statement) it works.

I'm having the same issue. Just wondering how long it will take to the SourceTree team to 'apply a patch' and resolve that annoying bug.

 

SourceTree 3.0.1 (205) on macOS Mojave (10.14.4)

I've the issue in May 2019.

- Sourcetree Mac 3.1.2 (216).

- Use embedded Git 2.20.1.

- macOS Mojave (10.14.3)

 

The test to reproduce it:

- "Actions / Create Patch…". Save the patch file.

- "Actions / Apply Patch…". Select the previous created patch file.

Ran into same problem today several times.  SourceTree 3.1.2 on a Mac.

My patch includes diff for four files. 

I tried the suggestion above "remove the header and footer info (Text before the first `diff` and the last two lines (double dashes and version info(?))" . but the file still does not work, i still get "this is not a valid patch file"

Fixed in 3.2!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Sourcetree

Sourcetree for Windows - CVE-2019-11582 - Remote Code Execution vulnerability

A vulnerability has been published today in regards to Sourcetree for Windows.  The goal of this article is to give you a summary of information we have gathered from Atlassian Community as a st...

4,895 views 0 12
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you