私の問題は、ファイルを変更したことです。たとえば、README に新しい行 ' this for my testing line ' を追加し、ファイルを保存してから、次のコマンドを発行しました。
git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: README
#
no changes added to commit (use "git add" and/or "git commit -a")
git add README
git commit -a -m 'To add new line to readme'
コードを GitHub にプッシュしませんでした。ここで、このコミットをキャンセルしたいと思います。
このために、私は使用しました
git reset --hard HEAD~1
しかし、新しく追加された ' this for my testing line ' という行が README ファイルから失われました。これは起こらないはずです。そこにコンテンツが必要です。コンテンツを保持し、ローカル コミットをキャンセルする方法はありますか?