両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン |
linux:using_diff_and_patch [2022/09/30 05:51] – [参考文献] ともやん | linux:using_diff_and_patch [2022/10/01 05:49] (現在) – [参考文献] ともやん |
---|
====== diff と patch の使い方...🤔 ====== | ====== diff と patch の使い方...🤔 ====== |
| |
| ===== diff の使い方 ===== |
| |
| ==== 色付きの出力 diff [--color=auto] ==== |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <b class=GRN>$</b> <b class=HIY>diff</b> -u0 --label build.sh --label build.sh --color=auto build.sh.org build.sh |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| <b class="BOLD">--- build.sh</b> |
| <b class="BOLD">+++ build.sh</b> |
| <b class=CYN>@@ -1 +1 @@</b> |
| <b class=RED>-#!/bin/sh</b> |
| <b class=GRN>+#!/bin/sh -x</b> |
| <b class=CYN>@@ -161,2 +161,2 @@</b> |
| <b class=RED>- yum update -y</b> |
| <b class=RED>- yum install -y epel-release </b> |
| <b class=GRN>+ sudo yum update -y</b> |
| <b class=GRN>+ </b> |
| <b class=CYN>@@ -164 +164,3 @@</b> |
| <b class=RED>- if echo $output | grep " 7."; then</b> |
| <b class=GRN>+ if echo $output | grep "Fedora"; then</b> |
| <b class=GRN>+ OSTYPE=FEDORA</b> |
| <b class=GRN>+ elif echo $output | grep " 7."; then</b> |
| <b class=CYN>@@ -171,0 +174,4 @@</b> |
| <b class=GRN>+ if [ ! "${OSTYPE}" = "FEDORA" ] ; then</b> |
| <b class=GRN>+ sudo yum install -y epel-release</b> |
| <b class=GRN>+ fi</b> |
| <b class=GRN>+ </b> |
| <b class=CYN>@@ -187,3 +193,3 @@</b> |
| <b class=RED>- elif [ "${OSTYPE}" = "CENTOS8" ] || [ "${OSTYPE}" = "CENTOS9" ] ; then</b> |
| <b class=RED>- dnf -y groupinstall "Development Tools"</b> |
| <b class=RED>-</b> |
| <b class=GRN>+ #elif [ "${OSTYPE}" = "CENTOS8" ] || [ "${OSTYPE}" = "CENTOS9" ] ; then</b> |
| <b class=GRN>+ elif [ "${OSTYPE}" = "FEDORA" ] || ["${OSTYPE}" = "CENTOS8" ] || [ "${OSTYPE}" = "CENTOS9" ] ; then</b> |
| <b class=GRN>+ sudo dnf -y groupinstall "Development Tools"</b> |
| <b class=CYN>@@ -195 +201 @@</b> |
| <b class=RED>- yum -y install git cmake</b> |
| <b class=GRN>+ sudo yum -y install git cmake</b> |
| <b class=CYN>@@ -198 +204 @@</b> |
| <b class=RED>- yum -y install libtool autoconf autoheader automake wget go clang patch expat-devel</b> |
| <b class=GRN>+ sudo yum -y install libtool autoconf automake wget golang clang patch expat-devel</b> |
| <b class=CYN>@@ -506 +512,2 @@</b> |
| <b class=RED>- git clone https://github.com/litespeedtech/third-party.git</b> |
| <b class=GRN>+ git clone --depth 1 https://github.com/litespeedtech/third-party.git</b> |
| <b class=GRN>+ patch -p0 < third-party-scripts.patch</b> |
| </pre></html></WRAP> |
| </WRAP> |
| <wrap em>※diff の色付き出力は diffutils-3.4 以降の新機能である🤤</wrap>\\ |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <b class=GRN>$</b> <b class=HIY>rpm</b> -qa | grep diffutils |
| </pre></html></WRAP> |
| <WRAP color_result><html><pre> |
| <b class=RED>diffutils</b>-<b class=DiYE>3.8</b>-2.fc36.x86_64 |
| </pre></html></WRAP> |
| </WRAP> |
| |
| [[https://savannah.gnu.org/forum/forum.php?forum_id=8639|GNU diff utilities - News: diffutils-3.4 released [stable] [Savannah]]]\\ |
| <WRAP group mincode> |
| <WRAP left half column><code> |
| NEWS |
| |
| * Noteworthy changes in release 3.4 (2016-08-08) [stable] |
| |
| ** New features |
| |
| diff accepts two new options --color and --palette to generate |
| and configure colored output. --color takes an optional argument |
| specifying when to colorize a line: --color=always, --color=auto, |
| --color=never. --palette is used to configure which colors are used. |
| </code></WRAP> |
| <WRAP left half column><code> |
| ニュース👀 |
| |
| * リリース 3.4 (2016-08-08) [安定版] の注目すべき変更点 |
| |
| ** 新機能😻 |
| |
| diff は、2 つの新しいオプション --color と --palette を受け入れて、色付きの出力を |
| 生成および構成します😃 --color は、線をいつ色付けするかを指定するオプションの引数を |
| 取ります: --color=always、--color=auto、--color=never🤤 --palette を使用して、使用 |
| する色を構成します🤔 |
| </code></WRAP> |
| </WRAP> |
| |
| ==== ヘルプ [--help] ==== |
| <WRAP color_term> |
| <WRAP color_command><html><pre> |
| <b class=GRN>$</b> <b class=HIY>diff</b> --help |
| </pre></html></WRAP> |
| <WRAP color_result_long><html><pre> |
| 使用法: diff [OPTION]... FILES |
| FILES を行ごとに比較します。 |
| |
| 長い形式のオプションで必須の引数は、それに対応する短い形式のオプションでも同様に必須です。 |
| --normal 通常の diff を出力する (デフォルト) |
| -q, --brief ファイルが異なるかどうかのみ表示する |
| -s, --report-identical-files 両方のファイルが同一であるかどうかのみ表示する |
| -c, -C NUM, --context[=NUM] コンテキスト diff 形式で前後 NUM (デフォルト: 3) 行を表示する |
| -u, -U NUM, --unified[=NUM] ユニファイド diff 形式で前後 NUM (デフォルト: 3) 行を表示する |
| -e, --ed ed スクリプトを出力する |
| -n, --rcs RCS 形式の diff を出力する |
| -y, --side-by-side 出力を2列にする |
| -W, --width=NUM 表示する列を最大 NUM (デフォルト: 130) 列にする |
| --left-column 共通行は左側の列のみ表示する |
| --suppress-common-lines 共通行の出力を抑止する |
| |
| -p, --show-c-function 変更がある C 関数を表示する |
| -F, --show-function-line=RE RE に一致する最も近い行を表示する |
| --label LABEL use LABEL instead of file name and timestamp |
| (can be repeated) |
| |
| -t, --expand-tabs 出力時にタブをスペースに展開する |
| -T, --initial-tab タブで始まる行は、前にタブを置いてそろえる |
| --tabsize=NUM タブ幅を NUM (デフォルト: 8) 列に設定する |
| --suppress-blank-empty 空の出力行の前後ではスペースまたはタブを抑止する |
| -l, --paginate pass output through 'pr' to paginate it |
| |
| -r, --recursive サブディレクトリーを再帰的に比較する |
| --no-dereference don't follow symbolic links |
| -N, --new-file 存在しないファイルを空ファイルとして扱う |
| --unidirectional-new-file 存在しない最初のファイルを空ファイルとして扱う |
| --ignore-file-name-case ファイル名の大文字と小文字を区別しない |
| --no-ignore-file-name-case ファイル名の大文字と小文字を区別する |
| -x, --exclude=PAT PAT に一致するファイルを除外する |
| -X, --exclude-from=FILE FILE 内のパターンに一致するファイルを除外する |
| -S, --starting-file=FILE ディレクトリーを比較する時に FILE から始める |
| --from-file=FILE1 すべての被演算子と FILE1 を比較する |
| FILE1 はディレクトリーでもよい |
| --to-file=FILE2 すべての被演算子を FILE2 を比較する |
| FILE2 はディレクトリーでもよい |
| |
| -i, --ignore-case ファイル内容の比較時に大文字と小文字を区別しない |
| -E, --ignore-tab-expansion タブ展開によって発生する違いを無視する |
| -Z, --ignore-trailing-space 行末にあるスペースを無視する |
| -b, --ignore-space-change スペース数により生じる違いを無視する |
| -w, --ignore-all-space すべてのスペースを無視する |
| -B, --ignore-blank-lines ignore changes where lines are all blank |
| -I, --ignore-matching-lines=RE ignore changes where all lines match RE |
| |
| -a, --text すべてのファイルをテキストとして扱う |
| --strip-trailing-cr 入力から CR (キャリッジリターン) を除去する |
| |
| -D, --ifdef=NAME output merged file with '#ifdef NAME' diffs |
| --GTYPE-group-format=GFMT GTYPE の入力グループを GFMT で整形する |
| --line-format=LFMT すべての入力行を LFMT で整形する |
| --LTYPE-line-format=LFMT LTYPE 入力行を LFMT で整形する |
| これらの書式整形オプションは -D/--ifdef に適用される diff の出力をきれいに |
| 見えるように制御するために提供されます。 |
| LTYPE is 'old', 'new', or 'unchanged'. GTYPE is LTYPE or 'changed'. |
| GFMT でのみ指定できる書式: |
| %< FILE1 からの行 |
| %> FILE2 からの行 |
| %= FILE1 と FILE2 で共通の行 |
| %[-][WIDTH][.[PREC]]{doxX}LETTER printf 書式の LETTER |
| LETTER は次の通りです。ただし古いグループでは小文字です: |
| F 最初の行番号 |
| L 最後の行番号 |
| N 行数 = L-F+1 |
| E F-1 |
| M L+1 |
| %(A=B?T:E) A と B が等しい場合は T、等しくない場合は E |
| LFMT でのみ指定できる書式: |
| %L 行の内容 |
| %l 行末にあるすべての種類の改行文字を除いた行の内容 |
| %[-][WIDTH][.[PREC]]{doxX}n printf 書式の入力行 |
| GFMT と LFMT の両方で指摘できる書式: |
| %% % |
| %c'C' 単一文字 C |
| %c'\OOO' 八進数コード OOO |
| C 文字 C (他の文字も同様に表す) |
| |
| -d, --minimal 差分の大きさが最小となるように違いを検出する |
| --horizon-lines=NUM 差分の前後にある共通部分を NUM 行保持する |
| --speed-large-files 巨大なファイルに小さな差分が分散していると仮定する |
| --color[=WHEN] color output; WHEN is 'never', 'always', or 'auto'; |
| plain --color means --color='auto' |
| --palette=PALETTE the colors to use when --color is active; PALETTE is |
| a colon-separated list of terminfo capabilities |
| |
| --help このヘルプを表示して終了する |
| -v, --version バージョン情報を表示して終了する |
| |
| FILES are 'FILE1 FILE2' or 'DIR1 DIR2' or 'DIR FILE' or 'FILE DIR'. |
| --from-file または --to-file が与えられた場合、FILE に制限はありません。 |
| If a FILE is '-', read standard input. |
| 終了コードは、入力ファイルが同じ場合は 0、入力ファイルが異なる場合は 1、 |
| 問題が発生したときは 2 になります。 |
| |
| Report bugs to: bug-diffutils@gnu.org |
| GNU diffutils のホームページ: <https://www.gnu.org/software/diffutils/> |
| General help using GNU software: <https://www.gnu.org/gethelp/> |
| </pre></html></WRAP> |
| </WRAP> |
| |
===== 参考文献 ===== | ===== 参考文献 ===== |
| [[https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/8/html/packaging_and_distributing_software/patching-software_preparing-software-for-rpm-packaging|2.6. ソフトウェアへのパッチの適用 Red Hat Enterprise Linux 8 | Red Hat Customer Portal]]\\ |
[[https://atmarkit.itmedia.co.jp/ait/articles/1705/11/news013.html|【 patch 】コマンド――テキストファイルに差分を適用する(応用編):Linux基本コマンドTips(108) - @IT]]\\ | [[https://atmarkit.itmedia.co.jp/ait/articles/1705/11/news013.html|【 patch 】コマンド――テキストファイルに差分を適用する(応用編):Linux基本コマンドTips(108) - @IT]]\\ |
[[https://qiita.com/astro_super_nova/items/e30dcaf4d106deebc63c|Linuxエンジニアらしいパッチのつくりかた - Qiita]]\\ | [[https://qiita.com/astro_super_nova/items/e30dcaf4d106deebc63c|Linuxエンジニアらしいパッチのつくりかた - Qiita]]\\ |
[[qita>rana_kualu/items/09d2dd379019b8ef0335|git diffの全オプション一覧 - Qiita]]\\ | [[qita>rana_kualu/items/09d2dd379019b8ef0335|git diffの全オプション一覧 - Qiita]]\\ |
[[https://beyondjapan.com/blog/2019/08/git-diff/|git diff で作ったパッチはどうやって当てるのか(そもそも git でパッチ | 株式会社ビヨンド]]\\ | [[https://beyondjapan.com/blog/2019/08/git-diff/|git diff で作ったパッチはどうやって当てるのか(そもそも git でパッチ | 株式会社ビヨンド]]\\ |
[[https://mrgoofy.hatenablog.com/entry/20101019/1287500809|]]\\ | [[https://mrgoofy.hatenablog.com/entry/20101019/1287500809|diff & patch コマンドでのパッチを適用する方法 - hogehoge foobar Blog Style Beta]]\\ |
[[https://linuxjm.osdn.jp/html/GNU_patch/man1/patch.1.html|]]\\ | [[https://linuxjm.osdn.jp/html/GNU_patch/man1/patch.1.html|Man page of PATCH]]\\ |
[[https://manpages.ubuntu.com/manpages/bionic/ja/man1/diff.1.html|]]\\ | [[https://manpages.ubuntu.com/manpages/bionic/ja/man1/diff.1.html|Ubuntu Manpage: diff - 2 つのファイル間の違いを探す]]\\ |
[[https://atmarkit.itmedia.co.jp/ait/spv/1704/13/news021.html|]]\\ | [[https://atmarkit.itmedia.co.jp/ait/spv/1704/13/news021.html|【 diff 】コマンド(基本編)――テキストファイルの差分を出力する:Linux基本コマンドTips(102) - @IT]]\\ |
[[https://atmarkit.itmedia.co.jp/ait/spv/1704/14/news011.html|]]\\ | [[https://atmarkit.itmedia.co.jp/ait/spv/1704/14/news011.html|【 diff 】コマンド(基本編その2)――テキストファイルの差分をcontext形式などで出力する]]\\ |
| [[https://future-architect.github.io/articles/20200610/|人生を豊かにする文字列diff入門 | フューチャー技術ブログ]]\\ |
| **diff**\\ |
| [[https://unix.stackexchange.com/questions/196565/how-to-color-diff-output|bash - How to color diff output? - Unix & Linux Stack Exchange]]\\ |
| [[https://wiki.archlinux.jp/index.php/%E3%82%B3%E3%83%B3%E3%82%BD%E3%83%BC%E3%83%AB%E3%81%AE%E3%82%AB%E3%83%A9%E3%83%BC%E5%87%BA%E5%8A%9B|コンソールのカラー出力 - ArchWiki]]\\ |
| **diff, match, patch**\\ |
| [[git>google/diff-match-patch|google/diff-match-patch: Diff Match Patch is a high-performance library in multiple languages that manipulates plain text.]]\\ |
| [[git>diff-match-patch-python/diff-match-patch|diff-match-patch-python/diff-match-patch: Diff Match Patch is a high-performance library in multiple languages that manipulates plain text.]]\\ |
| [[qita>iotas/items/05f90dc66ef6a69ab4c6|google-diff-match-patchを使ってかんたんに文章比較(Diff)してみる - Qiita]]\\ |
| |
| ==== 付録 ==== |