git diff コマンド

パッチを作成する

$ git diff > diff.patch

パッチを適用する

$ patch -p1 < diff.patch
こちらのページを参照

ドキュメント:

git-diff Documentation | Git [Official]

参考:

Git で変更をパッチファイルにする/patch コマンドで適用する – Qiita

Git でパッチファイルを作成する | まくまくノート

Create patch or diff file from git repository and apply it to another different git repository – Stack Overflow

--no-prefix オプション

参考:

Git でパッチファイルを作成する | まくまくノート

git diff を patch で扱える形式にする | Bye Bye Moore

普通の patch コマンドで取り込める diff ファイルを git で作成する | kanonji’s diary

--relative オプション

参考:

git diff の出力で相対パスを使うようにする | まくまくノート

Git で特定のディレクトリ以下の diff を見るときは、relative オプションを使う – Qiita

--src-prefix / --dst-prefix オプション

参考:

git diff output relative path? – Stack Overflow

git format-patch コマンド

ドキュメント:

git-format-patch Documentation | Git [Official]

参考:

git format-patchで外に出す用のパッチを生成する | Bye Bye Moore

Git で patch を作成して適用する手順のメモ | Hello, world! s21g

Creating and appying Git patches (dkorpar) – GitHub Gist

How to apply a Git patch to a file with a different name and path? – Stack Overflow

git apply コマンド

参考:

git diff で作ったパッチはどうやって当てるのか/そもそも git でパッチ | 株式会社ビヨンド

git apply を dry run する方法 | gotohayato

git am コマンド

ドキュメント:

git-am | Git Documentation [Official]

参考:

git am で他人のコミットをパッチとして当てる方法 – Qiita

How to apply a Git patch to a file with a different name and path? – Stack Overflow

How to apply a git patch from one repository to another? – Stack Overflow

git apply と git am の違い

参考:

What is the difference between git am and git apply? – Stack Overflow

パッチにするコミットの範囲を指定する書き方

参考:

git diff とか format-patch で特定コミットとその直前コミットを指定する – Qiita

パッチのフォーマット

参考:

What is the format of a patch file? – Stack Overflow

diff コマンド

こちらのページを参照

参考:

Linux エンジニアらしいパッチのつくりかた – Qiita

diff & patch コマンドでのパッチを適用する方法 | hogehoge foobar Blog Style Beta

patch コマンド

パッチを適用する

$ patch -p1 < diff.patch

参考:

patch コマンドでパッチ適用 – Qiita

pacth コマンドの当て方/適用方法 | ex1-lab

patch – 差分ファイルをオリジナルファイルに適用 | Webkaru

patch コマンド – ファイルにパッチファイルを適用する | Linuxコマンド.NET

patch コマンドの使い方 | UNIX/Linuxの部屋

パッチの作り方/当て方/戻し方 | 日本 KDE ユーザ会

patch コマンド – テキストファイルに差分を適用する 基本編 | @IT

Man page of PATCH | JM Project

patch – diff 出力を使用してファイルを変更する | IBM Documentation

patch(1) | man ページ (nxmnpg.lemoda.net)

patch – Wikipedia

When patching what’s the difference between arguments -p0 and -p1? – Unix & Linux Stack Exchange

-pnum オプション

パッチ内で指定されているパスの階層を上位から幾つ削るかを指定する。

パッチが foo/bar/baz/qux.ext というパスに対して生成されていた場合

  • -p0foo/bar/baz/qux.ext に適用
  • -p1bar/baz/qux.ext に適用
  • -p2baz/qux.ext に適用
  • -p3qux.ext に適用

参考:

patch コマンド -p オプションの覚え書き | ザリガニが見ていた…。

patch コマンドの -p オプションについて | 小粋空間

patch -p0 コマンドで適用できるパッチを作成する | mario s note

.rej ファイル

参考:

Dealing with Rejection | Bread & Circuits

Handling Patch Rejects | eLinux.org

partially applying a patch | Python Tales and Plone Stories

How to read .rej files – Stack Overflow

Running “patch” without generating *.orig and *.rej files – Unix & Linux Stack Exchange

What are .rej files which are created during merge – Stack Overflow

.orig ファイル

参考:

How to prevent patch from creating backup files? – Super User

ファイルからキャリッジリターンを取り除く

リポジトリ内にあるテキスト形式のファイルからキャリッジリターンを全て取り除く。

$ git grep -Il '' | xargs perl -pi -e 's/\r//'

キャリッジリターン以外の変更を確認する。

$ git diff --ignore-cr-at-eol

改行コードを LF から CRLF に変換する。

$ perl -pi -e 's/\n/\r\n/' filename.txt

参考:

Remove carriage return in Unix – Stack Overflow

How to list all text (non-binary) files in a git repository? – Stack Overflow

How to add a carriage return before every newline? – Unix & Linux Stack Exchange

How do I replace lines in the middle of a file with Perl? – Stack Overflow

特定のコミットをパッチにする

ハッシュを指定してコミットをパッチにする。

$ git diff 12345abcd~..12345abcd > diff.patch

参考:

Show diff between commits – Stack Overflow

バイナリのパッチを作成する

参考:

Git でバイナリパッチを作ってみよう (git diff --binary) – Qiita

How can I diff binary files in git? – Super User

Delta

リポジトリ:

dandavison/delta: A Syntax-Highlighting Pager for Git, Diff, and Grep Output – GitHub

ドキュメント:

Documentation | Delta

参考:

git format-patch を side-by-side で見れないかと思ったら delta で見れた | 三輪晋

記事をシェアする:
タグ:

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

Protected by reCAPTCHA