Applying a patch is the easy part. Taking it back out again is a thing I’d rather not do by hand, and patch has a switch for it.
patch -R g.txt < f.patch
-R (--reverse) tells patch to assume the patch was made with the old and new files swapped. In effect it applies the patch backwards. Here is a tiny round trip with a patch made by diff -u, where line two changes from two to 2:
patch g.txt < f.patch
patching file g.txt
patch -R g.txt < f.patch
patching file g.txt
After the first command the file said one 2 three, after the second one it was back to one two three.
Before reversing something bigger, combine it with --dry-run. In a test, patch -R --dry-run h.txt < f.patch printed checking file h.txt and changed nothing.
Two caveats. First, reversing only works while the file still looks like the patched version. If you edited the same lines afterwards, hunks can be rejected. Second, applying a patch that is already applied is not harmless either. When patch -N ran on a file that already had the change, it said Reversed (or previously applied) patch detected! Skipping patch. and also wrote a h.txt.rej file next to it, so look for stray .rej files afterwards.
If you want a safety net, -b keeps the original as k.txt.orig before patching.
Further reading: patch(1) manual page