您的位置:首页 > 运维架构 > Linux

如何补丁1个文件(linux diff patch)

2015-04-12 08:54 507 查看
目的:为文件打补丁

OS:Linux

方法:

diff -uN

patch --p0

具体例子:

file 内容OLD

打补丁为新文件file,内容NEW

方法:

1 分别创建file, fileNew,内容分别是OLD NEW

2 制作补丁

diff file fileNew >this.patch

查看制作的补丁

[root@gdc1000 patch]# cat this.patch

1c1

< OLD

---

> NEW

3 打补丁

patch < this.patch

出错,错误是
patch: **** Only garbage was found in the patch input.

4 查看file的内容,没有变化。

5 重新制作补丁

[root@gdc1000 patch]# diff -u file fileNew > this.patch

[root@gdc1000 patch]# cat this.patch

--- file    2015-04-12 08:57:40.925824818 +0800

+++ fileNew    2015-04-12 08:58:02.853824804 +0800

@@ -1 +1 @@

-OLD

+NEW

[root@gdc1000 patch]# patch < this.patch

[root@gdc1000 patch]# patch < this.patch

patching file file

[root@gdc1000 patch]# cat file

NEW

[root@gdc1000 patch]#

6 git diff is the same to diff files
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: