git reset: Usage, Options & Common CI Errors
git reset rewinds your branch to a commit and decides what happens to staged and working changes.
Reset is the main "undo commits" tool. The mode (--soft/--mixed/--hard) controls how much it touches.
What it does
git reset moves the current branch ref to a target commit. --soft keeps the index and working tree, --mixed (default) resets the index, --hard resets index and working tree, discarding changes.
Common usage
Terminal
git reset --soft HEAD~1 # undo commit, keep changes staged
git reset HEAD~1 # undo commit, unstage changes
git reset --hard origin/main # match remote, discard local work
git reset HEAD file.txt # unstage one fileOptions
| Flag | What it does |
|---|---|
| --soft | Move HEAD only; keep index and working tree |
| --mixed | Default: reset index, keep working tree |
| --hard | Reset index and working tree (destructive) |
| --merge / --keep | Reset but try to preserve local changes |
Common errors in CI
--hard silently discards uncommitted work and there is no "error" - that is the danger. If you reset too far, recover with git reflog to find the prior HEAD and git reset --hard <sha> back to it. Note: reset does NOT remove untracked files; use git clean for those.
Related guides
git restore: Usage, Options & Common CI Errorsgit restore discards working-tree changes or unstages files. Reference for --staged, --source, --worktree, an…
git revert: Usage, Options & Common CI Errorsgit revert undoes a commit by creating a new inverse commit, keeping history intact. Reference for -m, --no-c…
git reflog: Usage, Options & Common CI Errorsgit reflog records where HEAD and branches have been, so you can recover lost commits. Reference for show, ex…
git clean: Usage, Options & Common CI Errorsgit clean removes untracked files from the working tree. Reference for -n, -f, -d, -x, and the "would clobber…