In this post, 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.
- Let us suppose we are in a condition where we have made 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 made.
- 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 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.
Let's create a patch and then apply patch:
How to create a patch
First of all, let's make some changes to a file. For now, I am going to add one dummy function in some file named as ImportDefault.js.
Now, let's create patch of this file. We can right click on the modified file and select option Tortoise SVN and then choose Create patch option.
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.
Let's 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.
We can see how the patch file will look. It has all the information regarding the modifications that we have made.
As we can see, we had added one function in our file and it's clearly visible in patch file in New Modification Section.
Now let's 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.
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.
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.
After 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 the original and the modified file.
Now, we can see that the file we had reverted now has all the changes previously made by us.
I hope you like the post. :)