# How to Revert to a Previous Commit in Git (Safely)

DevFeed: [How to Revert to a Previous Commit in Git (Safely)](<https://devfeed.tech/articles/how-to-revert-to-a-previous-commit-in-git-safely-119472.md>)

Original publisher: [Read original article](<https://markodenic.com/git-revert-to-commit/>)

Author: Marko

Published: 2026-11-05T09:00:00Z

Content type: tutorial

Language: en

Sources: [Marko Denic Blog](<https://devfeed.tech/sources/marko-denic-blog.md>)

Topics: [Git](<https://devfeed.tech/topics/git.md>)

Tags: [branch](<https://devfeed.tech/tags/branch.md>), [changes](<https://devfeed.tech/tags/changes.md>), [checkout](<https://devfeed.tech/tags/checkout.md>), [commit](<https://devfeed.tech/tags/commit.md>), [commits](<https://devfeed.tech/tags/commits.md>), [delete](<https://devfeed.tech/tags/delete.md>), [file](<https://devfeed.tech/tags/file.md>), [git](<https://devfeed.tech/tags/git.md>), [hash](<https://devfeed.tech/tags/hash.md>), [history](<https://devfeed.tech/tags/history.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [lease](<https://devfeed.tech/tags/lease.md>), [leave](<https://devfeed.tech/tags/leave.md>), [local](<https://devfeed.tech/tags/local.md>), [look](<https://devfeed.tech/tags/look.md>), [merge](<https://devfeed.tech/tags/merge.md>), [mistakes](<https://devfeed.tech/tags/mistakes.md>), [recover](<https://devfeed.tech/tags/recover.md>), [reset](<https://devfeed.tech/tags/reset.md>), [safely](<https://devfeed.tech/tags/safely.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>)

## AI overview

Choose the command based on whether the commits were pushed. For shared, pushed work, `git revert` adds a new commit that reverses changes while preserving history; use `--no-commit` to combine multiple reverts, and `-m 1` when reverting a merge to keep the branch it was merged into. For local commits, `git reset` moves the branch pointer: `--soft` keeps changes staged, `--mixed` (the default) leaves them unstaged, and `--hard` discards them, including uncommitted work. Check `git status` and stash work before a hard reset. Resetting pushed commits requires a force push that rewrites shared history; `--force-with-lease` checks for intervening commits, and the article recommends doing this only on your own branch. To inspect an old commit without changing the branch, use detached HEAD; restore a single file with `git restore --source`; recover a reset position using `git reflog`. The article says reflog can usually recover commits, but not uncommitted changes.

## Source excerpt

Go back to a previous commit in Git: git revert for pushed work, git reset --soft, --mixed and --hard for local commits, restoring one file, reverting merges, and recovering from mistakes with reflog.