git diff コマンド
パッチを作成する
$ git diff > diff.patch
パッチを適用する
$ patch -p1 < diff.patch
参考:
Git で変更を patch ファイルにする / patch コマンドで適用する – Qiita
Git でパッチファイルを作成する | まくまく Git ノート
git-diff Documentation | Git [Official]
--no-prefix オプション
参考:
Git でパッチファイルを作成する | まくまく Git ノート
--relative オプション
参考:
git diff の出力で相対パスを使うようにする | まくまく Git ノート
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
git apply コマンド
参考:
git apply を dry run する方法 | gotohayato
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 コマンド
参考:
diff & patch コマンドでのパッチを適用する方法 | hogehoge foobar Blog Style5
patch コマンド
参考:
patch コマンド – テキストファイルに差分を適用する 基本編 | @IT
diff差分ファイルをオリジナルファイルに適用 | Webkaru
Man page of PATCH | JM Project
-pnum オプション
パッチ内で指定されているパスの階層を上位から幾つ削るかを指定する。
パッチが foo/bar/baz/qux.rb
というパスに対して生成されていた場合
-p0
:foo/bar/baz/qux.rb
に適用-p1
:bar/baz/qux.rb
に適用-p2
:baz/qux.rb
に適用-p3
:qux.rb
に適用
参考:
patch コマンド -p オプションの覚え書き | ザリガニが見ていた…。
.rej ファイル
参考:
Running “patch” without generating *.orig and *.rej files – Unix & Linux Stack Exchange
What are .rej files which are created during merge – Stack Overflow
partially applying a patch | Python Tales and Plone Stories
.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