git apply
git
書き方
git apply [--check|-3] <patch>diffファイルを今の作業ツリーに当てます。コミットを作らず、パッチに書かれた作者も読まないので、メールで届いたパッチはamで当てるのが筋です。
よく使うオプション
| オプション | 意味 |
|---|---|
| --check | report whether it would apply, change nothing |
| -3 | fall back to a three-way merge and leave conflict markers |
| --index | apply to the working tree and stage it |
| --cached | apply to the index only |
| -R | apply in reverse, undoing the patch |
| -p<n> | strip n leading path components |
| --stat | show what the patch touches |
例
git apply --check fix.patchtells you if it fits before you try
git apply -3 fix.patchapplies it and leaves conflicts to resolve by hand
git apply -R fix.patchtakes an applied patch back out
取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。
読み方
- 角括弧 [ ] は省いてよい部分です。
- 三点 … は複数並べられるという意味です。
- オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。
よくある質問
Q. git apply は何をしますか。
diffファイルを今の作業ツリーに当てます。コミットを作らず、パッチに書かれた作者も読まないので、メールで届いたパッチはamで当てるのが筋です。
Q. どう打ちますか。
git apply [--check|-3] <patch> — 角括弧は省いてよい部分です。
Q. よく使うオプションはいくつですか。
ここにまとめたのは7個です。全部は man git にあります。このコマンドはgitの仲間です。
関連するコマンド
man ページ: man git-apply