Apply failed hunk with TortoiseSVN
Asked Answered
G

5

14

How can I apply a patch with TortoiseSVN that initially fails with one or more rejected hunks?

Is it possible to use TortoiseMerge to review the patch/the failed result and pick the lines I want to be applied?

If not, what do I do after I encounter failed hunks? Editing patch files by hand does not seem to be the perfect solution (apart from not knowing how to "fix" them)

Gratitude answered 9/10, 2013 at 8:28 Comment(1)
I'm not sure if Git can do better, but IIRC with Git you get a conflicted file including conflict markers which you can then resolve.Gratitude
H
6

One way I can think of is:

  1. Switch the (clean) working copy to the base revision of the patch
  2. Apply the patch
  3. commit to a branch
  4. Switch to the trunk or your working branch, wherever you want to apply the patch.
  5. Perform a typical svn merge of the revision in (3) to your working copy.
Haymo answered 11/7, 2014 at 16:3 Comment(0)
E
3

I ended up using the built-in Visual Studio merge tool as described here: Compare two files in Visual Studio 2012. I like the Visual Studio diff tool better than TortoiseSVN's anyway.

You still need another branch/trunk to apply the patch to but this way you don't need to commit it first.

  1. Switch the (clean) working copy to the base revision of the patch
  2. Apply the patch
  3. Use one of the methods described in that link to compare the files.
Equivalence answered 4/5, 2015 at 15:11 Comment(1)
You can actually use any comparison tool, such as TortoiseMerge (my preference) at step 3. So the the answer to ye old OP's question is "yes, you can do that". I was using TortoiseSVN's "diff later" feature to do this, but as long as you compare the file from which you created the patch to the file receiving the patch, it works.Inexertion
S
0

In our situation; The problem was caused by applying the patch twice. When the first patch created new files and were not removed before applying the patch again.

So removing the files created by the first patch run solved our problem.

Slantwise answered 23/9, 2020 at 10:20 Comment(0)
A
0

My solution is similar to Yakov Galkas but without using an extra branch:

  1. Switch the working to the base revision of the patch
  2. Apply the patch. There shouldn't be failed hunks now.
  3. Update to HEAD revision. You will probably get merge conflicts.
  4. Solve the merge conflicts as usual, you don't have to manually fix patch files.
Aluin answered 28/10, 2020 at 14:38 Comment(0)
G
0

My "failed hunk" message was probably caused by different versions of TortoiseSVN or SVN.

I reverted my branch to the revision specified inside my colleague's patch, then I applied it, ignored the "failed hunk" message, created my patch from changes introduced by the colleague's patch, and compared both patches. There were a lot of occurrences of the same difference: "(revision 0)" vs. "(nonexistent)". So I ignored them too. That's it!

Geoponics answered 21/7, 2022 at 8:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.