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?
Copy the diff file to the root of your repository, and then do:
More information about the
applycommand is available on its man page.By the way: A better way to exchange whole commits by file is the combination of the commands
git format-patchon the sender and thengit amon the receiver, because it also transfers the authorship info and the commit message.If the patch application fails and if the commits the diff was generated from are actually in your repo, you can use the
-3option ofapplythat tries to merge in the changes.It also works with Unix pipe as follows: