People usually use some tool to apply patch to a target system which in addition to applying a patch also manage the history the patches so that it can be reverted in case the patch goes wrong. The patch history usually contains below details:
- The new files that were added in the patch, while reverting the patch those files should be deleted.
- The files that were deleted by the patch, while reverting the patch the deleted files should be restored back.
- The files that were modified by the patch, while reverting the patch the modified files should be restored back.
Extra steps to be done after applying patch:
To make git track the changes done in patch, you just need to perform 2 extra commands
git add . : This command will track all the files that have been modififed, added or deleted in the system.
git commit -m “Applying Patch” : This command actually adds the files information tracked by previous command with a message in the git system
Steps to be done in reverting changes done by a patch:
Once you have all the information tracked in git it will become no-brainer to revert the patches.
To view the details of all the patches: You can use git log command that will provide you the list of all the patches that you have applied or reverts that you have done
sandy@sandy:~/test/app1$ git log
commit f622f1f97fc44f6897f9edc25f9c6aab8e425049
Author: sandy
Date: Thu Jun 19 15:19:53 2014 +0530
Patch 1 on release2
commit 9a1dd81c7799c2f83d897eed85914eecef304bf0
Author: sandy
Date: Thu Jun 19 15:16:52 2014 +0530
Release 2
commit 135e04c00b3c3d5bc868f7774a5f284c3eb8cb29
Author: sandy
Date: Thu Jun 19 15:16:28 2014 +0530
Release 1
Now Reverting a patch is as simple as executing a simple command git revert, with the commit id of the patch
git revert f622f1f97fc44f6897f9edc25f9c6aab8e425049
[master 0ba533f] q Revert "Patch 1 on release2"
1 file changed, 1 deletion(-)
If you run git log command, you will see the patch revert history as well
sandy@sandy:~/test/app1$ git log
commit 0ba533fda95ed4d7fcf0b7e6b23cd1a5589946a7
Author: sandy
Date: Thu Jun 19 15:20:24 2014 +0530
Revert "Patch 1 on release2"
This reverts commit f622f1f97fc44f6897f9edc25f9c6aab8e425049.commit f622f1f97fc44f6897f9edc25f9c6aab8e425049
Author: sandy
Date: Thu Jun 19 15:19:53 2014 +0530
Patch 1 on release2
commit 9a1dd81c7799c2f83d897eed85914eecef304bf0
Author: sandy
Date: Thu Jun 19 15:16:52 2014 +0530
Release 2
commit 135e04c00b3c3d5bc868f7774a5f284c3eb8cb29
Author: sandy
Date: Thu Jun 19 15:16:28 2014 +0530
Release 1
I hope this blog has given you a very different perspective of managing the patches, let me know your thoughts about this. Also if you have such more ideas do share with me.