git reset
Resetting to a previous commit
The git reset command moves the current branch pointer to a specified commit. The three modes control what happens to your working directory and staging area. For a comparison of reset versus revert, see the difference between git reset and revert.
Soft reset — keep changes staged
Use --soft to move the branch tip without touching the staging area or working directory. All changes from the reset commits remain staged and ready to recommit.
$ git reset --soft HEAD~1
Mixed reset — unstage changes (default)
Omitting a flag (or passing --mixed) moves the branch tip and clears the staging area, but leaves your working directory intact.
$ git reset HEAD~1
This is the most common way to undo your last commit while keeping the changes for further editing.
Hard reset — discard all changes
Warning:
--hardpermanently discards uncommitted changes in both the staging area and working directory. This cannot be undone unless the commits are still reachable viagit reflog.
$ git reset --hard HEAD~1
To reset all the way back to a specific commit hash:
$ git reset --hard <commit-hash>
Resetting to HEAD
Unstage all staged files
$ git reset HEAD
Discard all uncommitted changes
$ git reset --hard HEAD
Resetting a specific file
To unstage a single file without affecting the rest of the staging area:
$ git reset HEAD <file>
This leaves the working directory copy of the file unchanged — only the staged version is removed. You can verify what remains staged by running git diff --staged. If you need to discard working directory changes for a specific file instead, use git checkout -- <file>.
Once your code is ready, DeployHQ can deploy it to your servers automatically from any Git repository.