📘
git で誤ってコミットをリモートへ push してしまったので reset して取り消す
注意
複数人で作業している場合(たいはんがそうだと思いますが) 他のひとのタイムラインが混乱することがあるので、声をかけてから作業しましょう。
git で reset して push します
先頭から 1 つ
% git reset HEAD^
またはコミットID を指定
% git reset <コミットID>
git push して reject されたら...
error: failed to push some refs to 'ナントカカントカ'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
git push -f するのもテですが、 --force-with-lease のほうが安全かと。
% git push --force-with-lease
Discussion