Creating and applying patch in SVN

Hi Guys,
Today I am going to explain something about patch files in SVN. Let me explain what a patch is ?
A patch is text file that contains the modification that were made to a file.

Why is this useful? I got some points where I found it useful.

1.)Let us suppose we are in a condition, where we have done some changes to some file and we want other developers to know about the changes that we did to the specific file without committing the file. In a situation like this we can create the patch of that file and give this patch file to other developer so that he/she can see the changes that we have done.

2.)There can be a situation where we accidently revert the files that had lots of changes made by us. we simply can use the undo option to undo the changes but that can be a very hectic process. So in a situation like this Patch can be very helpful. If we have the patch of that file stored, then we can simply apply patch to
to get all the changes back that we lost by mistake.

We can also create patch of more than one file and can apply all those patch at once.

Lets create a patch and then apply patch:

How to create a patch:
First of all lets do some changes to a file. For now I am going to add one dummy function in some file named as ImportDefault.js.
now lets create patch of this file. We can right click on the modified file and select option Tortoise SVN and then choose Create patch option.

Select Create Patch Image
It will open a window where we can choose for which file we are going to create a patch. We can also set the constraints while making patch for a file by clicking on
option button.

savepatchlocationEdit (1)

Lets do not bother about it and click OK. It will open another window which will ask us to choose the location where patch file should be stored
we will save it in desktop.

DiffOptions

We can see how the patch file will look.It has all the information regarding the modifications that we have made.

PatchCopy

As we can see we had added one function in our file and its clearly visible in patch file in New Modification Section.

Now lets revert the file.As we see now, we have lost all the changes. So for getting those changes back we shall apply the patch.

Apply Patch: Now just right click on patch file and select TortoiseSVN option and then choose Apply Patch.

Choose Apply Patch Option

Now it will ask you the location where you want to patch the file so we choose the same location where our file is stored.Now we click ‘Select Folder’ option

applypatchlocationEdit (1)
It will now open another window where we can choose files to which we want to apply the patch option. select our file and click on patch selected item.

ChooseFolderToPatchAfter clicking on patch selected item We see that we have got our changes back.It also shows one file that will show the difference between original and modified file.

PatchApplied

Now We can see that the file we had reverted, now has all the changes previously made by us.

Thanks,

I hope you like the post. 🙂

One comment

  1. dineshramitc · February 14, 2015

    Reblogged this on Dinesh Ram Kali..

    Like

Leave a comment