fc2ブログ

[Git]新規追加したファイルを git diff で差分表示したい

ソースコードの修正をパッチファイルにしたいとき、以下のように git diff コマンドでパッチを作成するが、新規追加したファイルが patch ファイルに含まれていないことに気づいた。

git diff > hogehoge.patch

git status で状態を確認すると以下のような状態。

$ git status
On branch work
Untracked files:
(use "git add ..." to include in what will be committed)
hogehoge.txt



git add -N hogehoge.txt

"-N" オプション!!
これで、git diff で差分として表示されるようになる。
status を確認すると以下のようになっている。

$ git status
On branch work
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
new file: hogehoge.txt


あとは、git diff > hogehoge.patch でファイルに出力すれば、新規追加ファイルの内容もパッチファイルに出力することができる。

コメントの投稿

非公開コメント

プロフィール

hiiro

Author:hiiro

最新記事
カテゴリ
最新コメント
最新トラックバック
検索フォーム
RSSリンクの表示
リンク
QRコード
QR
Counter