Gitは状況に応じてさまざまな方法を提供しています — コミットされていない変更を破棄する、ステージングを解除する、最後のコミットを修正する、コミットを取り消す、またはリセットするなど。各状況に適切なツールを知ることは重要で、実用的なスキルです。
コミットされていない変更を元に戻す(ワーキングディレクトリ)
git restore <file> # discard unstaged changes to a file (revert to last commit)
git checkout -- <file> # older equivalent
git restore . # discard ALL unstaged changes (careful!)
git clean -fd # remove untracked files/directories
ステージングを解除する(変更は保持し、ステージングだけ解除)
git restore --staged <file>
git reset <file>
