简体   繁体   English

如何将diff应用于源代码?

[英]How to apply a diff to source code?

Someone sent me the output of a diff of my remote and their local. 有人向我发送了我的遥控器及其本地设备的差异输出。 My local is a clone of the remote with no changes. 我的本地是远程服务器的克隆,没有任何更改。 What is the best way to apply the diff to my local without manually going through it and making each change? 将diff应用于我的本地而不手动进行比较并进行每次更改的最佳方法是什么?

diff --git a/path b/path

The git apply command will take a patch and apply it to your local directory. git apply命令将获取一个补丁并将其应用到本地目录。 There is some good discussion here , and of course also the git-apply documentation . 有一些很好的讨论在这里 ,当然也git的申请文件

It depends on your workflow you can use git apply to apply a properly formatted patch. 您可以使用git apply来应用格式正确的补丁程序,具体取决于您的工作流程。 Alternatively you could have the other party push to a shared branch git push origin <branch> and you could pull their branch down and merge/rebase the changes. 或者,您可以让另一方推送到一个共享分支git push origin <branch> ,您可以下拉其分支并合并/重新设置更改。 Both of these are functionally equivalent, but the second option sports a little recordkeeping regarding your code sharing arrangement. 两者在功能上是等效的,但是第二种选择在代码共享安排方面保留一些记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM