Git Cheatsheet - Quick Git Command Reference

Quick reference for common Git commands. Search, copy, and use Git commands instantly.

Share
Back to Git Cheatsheet

git reset

Reset current HEAD to specified state

Syntax

git reset [options] [<commit>]

Common Options

OptionDescription
--softSoft reset: move HEAD only, keep staging and working tree
--mixedMixed reset (default): move HEAD and reset staging
--hardHard reset: move HEAD, reset staging and working tree
HEAD~nGo back n commits
<file>Unstage specific file

Examples

git reset HEAD file.txt

Unstage file

git reset --soft HEAD~1

Undo last commit keeping changes

git reset --hard HEAD~1

Permanently delete last commit and changes

git reset --hard origin/main

Force sync with remote main

Three Reset Modes Comparison

Working Directory State

Soft

Keep staging area and working tree

Mixed (default)

Keep working tree, clear staging area

Hard

Discard all changes (use with caution)

Safety Tips

Before --hard, consider git stash or backup branch. Lost commits can be recovered via git reflog

Related Commands

Related Tools

More Code & Dev Tools