gitpatchgit-patch

Git apply patch to specific file outside of git repo


I have two files, x_original.txt and x_updated.txt.

I used the following command to obtain a patch file:

git diff --no-index x_original.txt x_updated.txt > fix_something.patch

I now want to apply this patch to a file called x.txt.

The following is worth noting:

What git command can I use to apply this patch? Or another utility if necessary? And what modifications should I make to the patch file?


Solution

  • I found out how to do it using the patch command:

    patch -p1 x.txt fix_something.patch
    

    This utility appears to ignore the filenames specified in the patch file, so there's no need to modify anything there.