3
2

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 3 years have passed since last update.

git commit --amendを取り消したい

Posted at

はじめに

ローカルブランチで作業中にgit commit --amendをした際に取り消そうと思ったのに、キーボードの打ち間違えでエディタが保存となってしまって、困ったことが何回かあり、その解決方法をまとめました。

実行手順

  1. git reflogで、コミットの履歴が一覧表示されます。
    ※間違えて、initial commitにammendしてしまった場合
```sh:ターミナル
git reflog

02e93b2 HEAD@{0}: commit (amend): Initial commit
cd9c949 (origin/main, main) HEAD@{1}: checkout: moving from main to branch
cd9c949 (origin/main, main) HEAD@{2}: commit (amend): Initial commit
```
  1. git reset --soft HEAD@{番号}で、そのコミット履歴の過去の状態に戻ります。
```sh:ターミナル
git reset --soft HEAD@{2}
```
3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?