diff 命令和patch文件的使用

    xiaoxiao2021-03-25  76

    1. 使用diff命令

    现有text1.txt和text2.txt两个文件: text1.txt

    this is the first line this is the second line this is the thiid line

    text2.txt

    this is the first line this is the second line this is the third line

    两个文件的区别是第三行 third 单词有误。

    使用diff命令输出两个文件的区别:

    diff text1.txt text2.txt

    output:

    3c3 < this is thiid line --- > this is third line

    将diff输出保存为patch文件:

    diff text1.txt text2.txt > amend.patch

    2. patch文件的使用

    拿到amend.patch文件后,可以使用patch命令将其作用在text1.txt 或者 text2.txt

    amend.patch文件保存的是由text1.txt到text2.txt的修改,所以将amend.patch作用到text1.txt文件上,text1.txt就会变为text2.txt

    patch text1.txt amend.patch

    这时参看text1.txt:

    cat text1.txt

    output:

    this is first line this is second line this is third line

    text1.txt的单词错误已经改正,与文件text2.txt文件一致。

    amend.patch文件同样可以作用到text2.txt上,不过patch命令会探测到由text2.txt回退到text1.txt,这时需要加上-R参数:

    patch -R text2.txt amend.patch
    转载请注明原文地址: https://ju.6miu.com/read-33739.html

    最新回复(0)