Diff and Patch workflow

Simple workflow for using Diff and Patch.

Example file php.ini:

short_open_tag = Off
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
html_errors = On

Backup the original file twice

cp php.ini php.ini.orig
cp php.ini php.ini.edit

Modify .edit file

nano php.ini.edit
short_open_tag = On
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
log_errors = On
ignore_repeated_errors = On
ignore_repeated_source = On
report_memleaks = On
track_errors = On
html_errors = On
error_log = php_errors.log

Save.

Create .diff

diff php.ini.orig php.ini.edit > php.ini.diff
cat php.ini.diff
1,4c1,4
< short_open_tag = Off
< error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
< display_errors = Off
< display_startup_errors = Off
---
> short_open_tag = On
> error_reporting = E_ALL
> display_errors = On
> display_startup_errors = On
6,7c6,7
< ignore_repeated_errors = Off
< ignore_repeated_source = Off
---
> ignore_repeated_errors = On
> ignore_repeated_source = On
8a9
> track_errors = On
9a11
> error_log = php_errors.log

Apply patch

patch -p0 php.ini < php.ini.diff
cat php.ini

Revert patch

patch -R -p0 php.ini < php.ini.diff
cat php.ini

Delete .edit and .orig

rm php.ini.{edit,orig}