How to solve in source tree "One or more hunks were rejected in the patch you just applied" by always applying the patch version?

At the same level that I have my wwwroot, I copied a patch file created in source tree. The project is in ASP.Net core with angular. When I try to apply the patch from Actions - Apply patch - Browse to patch which is of extension diff, I get an error:

"One or more hunks were rejected in the patch you just applied, you will find these hunks in .rej files of the same name as the file affected. The files affected are: ... (followed by list of files - some of them appear to be listed twice)."

WHat is the best way to force the patch to completely override my local files? Preferably a completely non manual way, either from source tree or the command line.

If I well recall, in TFS you could unload a shelf and could even choose to keep just 'hunks' of shelves, examining the differences one by one, and then taking either server or local version, does something like that exist in source tree?



answered 6 months ago Marina Liu - MSFT #1

It’s mainly caused by the conflicts between the patched version and current HEAD version.

You can double check in your patch file, there has commit(s) that change the filename.ts, you just need to remove the conflict commit(s) from the patch file and apply again.

Such as below example, file 1.txt has conflicts during applying changes. And in the patch file, we find 1.txt is changed in the commit afcd075, then remove the commit from patch file (as below):

From afcd076e51a2768769fa3473df256c8d8f3eda14 Mon Sep 17 00:00:00 2001
From: marinaliu <[email protected]>
Date: Wed, 14 Mar 2018 17:03:22 +0800
Subject: [PATCH 3/6] 2

 1.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/1.txt b/1.txt
index 36a5641..b571927 100644
--- a/1.txt
+++ b/1.txt
@@ -1,3 +1,3 @@
\ No newline at end of file

Then use git apply patchfile to apply the changes again.

And if you also want to get filename.ts version from the patched commit to your HEAD version, you can use the commands:

git checkout <commit> -- filename.ts 
# As git checkout afcd076 -- 1.txt in the example
git commit

comments powered by Disqus