LoginSignup
2
2

More than 3 years have passed since last update.

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

Posted at

はじめに

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

実行手順

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

    ターミナル
    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
    
  2. git reset --soft HEAD@{番号}で、そのコミット履歴の過去の状態に戻ります。

    ターミナル
    git reset --soft HEAD@{2}
    
2
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
2
2