I have a .diff file created by a coworker, and would like to apply the changes listed in that diff file to my local branch of the exact same repository. I do not have access to that worker's pc or branch that was used to generate this diff file.
Obviously I could go line by line and retype everything, but i'd rather not subject the system to human error. What's the easiest way to do this?
It seems like you can also use the patch command. Put the diff in the root of the repository and run patch
from the command line.
patch -i yourcoworkers.diff
or
patch -p0 -i yourcoworkers.diff
You may need to remove the leading folder structure if they created the diff without using --no-prefix
.
If so, then you can remove the parts of the folder that don't apply using:
patch -p1 -i yourcoworkers.diff
The -p(n) signifies how many parts of the folder structure to remove.
More information on creating and applying patches here.
You can also use
git apply yourcoworkers.diff --stat
to see if the diff by default will apply any changes. It may say 0 files affected if the patch is not applied correctly (different folder structure).
Source: Stackoverflow.com