autosquash
@jthill が示唆したように、 git のオプションが存在します。
たとえば、私の場合、最初のケースを
$ git log --oneline --decorate
ddd4444 (HEAD, my-feature-branch) A fourth commit
ccc3333 A third commit
bbb2222 A second commit
aaa1111 A first commit
9999999 (master) Old stuff on master
スカッシュしたい最近の変更を次のように追加しHEAD~4
ます。
$ git add .
$ git commit --fixup aaa1111
[my-feature-branch eee5555] fixup! A first commit
したがって、私の履歴は次のようになります。
$ git log --oneline --decorate
eee5555 (HEAD, my-feature-branch) fixup! A first commit
ddd4444 A fourth commit
ccc3333 A third commit
bbb2222 A second commit
aaa1111 A first commit
9999999 (master) Old stuff on master
autosquash
byを使用してリベースすると、正しい場所$ git rebase --interactive --autosquash master
にコミットされたコミットが自動的に選択されます。--fixup
リベースとコミットメッセージの編集によるマージに続いて、コミットが正常にリベースされます!
魔法のように機能します!:)
ソース:思考ボット