15
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Git】直前のgit pushを取り消す方法

Last updated at Posted at 2022-08-24

はじめに

間違えたコミットをプッシュしてしまった場合などで、
それを取り消したい場合に使える方法です。

方法

履歴を残したくない場合

まずは直前のコミットをresetで取り消す

$ git reset --hard HEAD^

強制オプションの-fをつけてプッシュ

$ git push -f origin HEAD

履歴を残したい場合

resetではなくrevertを使用

$ git revert HEAD^

そしてプッシュ

$ git push origin HEAD

最後に

個人開発なら、特に理由が無ければresetでも良いかと思いますが、
チーム開発では履歴は残した方が良いかもです。

参考

15
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?