用diff和patch生成patch并应用

当我们想在原文件和新文件之间生成patch,并用这个patch文件,应用在原文件上快速完成更新时,可以使用以下步骤:

  • 用diff生成patch
    $ echo "12345\ntesting"> old_file 
    $ echo "125testing\ntesting1234"> new_file
    $ # We have 2 common ways to get the patch
    $ # The first way is :
    $ diff old_file new_file > file_patch
    $ # We can see the patch are generated by lines
    $ cat file_patch
    1c1
    < 12345\ntesting
    ---
    > 125testing\ntesting1234
    $ # The second way is :
    $ diff -c old_file new_file > c_file_patch
    $ # Then we can see the patch are generated by contents
    $ cat c_file_patch
    *** old_file    2018-12-27 21:06:57.922518425 +0800
    --- new_file    2018-12-27 21:07:11.551401751 +0800
    ***************
    *** 1 ***
    ! 12345\ntesting
    --- 1 ----
    ! 125testing\ntesting1234
    $ # We also can get one whole patch for files of the whole directories
    $ mkdir -p new_dir old_dir
    $ echo "123" > new_dir/test_1.txt
    $ echo "789testing" &g
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值