helen's blog

ずっとおもしろいことしてたいな。

納品物として大量のコミットが来て白目剥いた話

デザインさんに成果物を複数コミットで納品していただいたのですが
あるコミットで修正された内容がその後のコミットで戻されていたりとか...
その結果差分の取りこぼしがぽろぽろとあり手戻り発生したりとか....

すでにマージされた部分だし、
デザインさんと運用の仕方が異なるのは仕方がないことなので
git のコマンドで上手いこと差分を取り出せれば
デザインさんもシステムもお互いハッピーなのでは!?と思い調査

gitコマンド
git diff 反映するコミットの直前コミットのハッシュ値  反映するコミットの最終コミットのハッシュ値 --diff-filter=M
# コミットのイメージ
latest commit 
next commit
反映するコミットの最終コミット ← ここまで反映したい ← ここを使う
piyo commit 
fuga commit
hoge commit ← ここから反映したい
反映するコミットの直前コミット ← ここを使う
before commit 
older commit

2箇所のハッシュ値を使って差分をあぶり出してみました

git diff --diff-filterのオプション

diff-filter:指定した変更の差分が表示される
・M:修正
・A :追加
・C :コピー
・D :削除
・R :リネーム
今回は差分だけ見たかったので diff-fillter=M にしました

# --diff-filterのヘルプ 
--diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
           Select only files that are Added (A), Copied (C), Deleted (D), Modified
           (M), Renamed (R), have their type (i.e. regular file, symlink, submodule,
           ...) changed (T), are Unmerged (U), are Unknown (X), or have had their
           pairing Broken (B). Any combination of the filter characters (including
           none) can be used. When * (All-or-none) is added to the combination, all
           paths are selected if there is any file that matches other criteria in
           the comparison; if there is no file that matches other criteria, nothing
           is selected.

参考:git diff のとき変更したファイルだけを確認する - Qiita