If you have used git to deploy your Moodle code (git clone + git checkout), then once you have made the changes you need, you can get git to generate a patch file:
git diff changedfile.php > changed.patch
You can then save the patch file somewhere and re-apply it using "patch" if you refresh or upgrade your Moodle codebase.
We use that approach and store patch files in a directory structure that mirrors the Moodle codebase, and I have a custom bash script that works it's way through the structure, picks up the patch files and applies them.
Hope that helps - let me know if you need any more info.