Git apply patch to specific file outside of git repo

1.9k Views Asked by At

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:

  • x.txt is not in a git repo
  • the filenames x_original.txt and x_updated.txt are included in fix_something.patch which makes no sense because these files won't exist when I'm applying the patch

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?

1

There are 1 best solutions below

0
David Callanan On BEST ANSWER

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.