git でコミットの差分を適用


git cherry-pick --no-commit <commit1> #<commit2>...

オプション --no-commit(又は -n)を指定して任意コミットをチェリーピックすると、差分だけを適用できる。


git cherry-pick --no-commit b61ae28116cfe5c4cc8bcc027e489fe40a5d1bff


git help cherry-pick
       -n, --no-commit
           Usually the command automatically creates a sequence of commits.
           This flag applies the changes necessary to cherry-pick each named
           commit to your working tree and the index, without making any
           commit. In addition, when this option is used, your index does not
           have to match the HEAD commit. The cherry-pick is done against the
           beginning state of your index.

           This is useful when cherry-picking more than one commits' effect to
           your index in a row.


git diff <basecommit> <modifiedcommit> > patch.diff

git diff で差分のパッチを作成できる。

patch -p0 < patch.diff

パッチファイルはレポジトリのルートで -p0 (=ファイルパスをそのまま守る)で適用すれば良い。