git revert makes a new commit

git revert simply creates a new commit that is the opposite of an existing commit.

It leaves the files in the same state as if the commit that has been reverted never existed. For example, consider the following simple example:

$ cd /tmp/example
$ git init
Initialized empty Git repository in /tmp/example/.git/
$ echo "Initial text" > README.md
$ git add README.md
$ git commit -m "initial commit"
[master (root-commit) 3f7522e] initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
$ echo "bad update" > README.md 
$ git commit -am "bad update"
[master a1b9870] bad update
 1 file changed, 1 insertion(+), 1 deletion(-)

In this example the commit history has two commits and the last one is a mistake. Using git revert:

$ git revert HEAD
[master 1db4eeb] Revert "bad update"
 1 file changed, 1 insertion(+), 1 deletion(-)

There will be 3 commits in the log:

$ git log --oneline
1db4eeb Revert "bad update"
a1b9870 bad update
3f7522e initial commit

So there is a consistent history of what has happened, yet the files are as if the bad update never occurred:

$ cat README.md 
Initial text

It doesn't matter where in the history the commit to be reverted is (in the above example, the last commit is reverted - any commit can be reverted).

Closing questions

do you have to do something else after?

A git revert is just another commit, so e.g. push to the remote so that other users can pull/fetch/merge the changes and you're done.

Do you have to commit the changes revert made or does revert directly commit to the repo?

git revert is a commit - there are no extra steps assuming reverting a single commit is what you wanted to do.

Obviously, you'll need to push again and probably announce your balls-up to the team.

Indeed - if the remote is in an unstable state - communicating to the rest of the team that they need to pull to get the fix (the reverting commit) would be the right thing to do :).

Answer from AD7six on Stack Overflow
Top answer
1 of 7
389

git revert makes a new commit

git revert simply creates a new commit that is the opposite of an existing commit.

It leaves the files in the same state as if the commit that has been reverted never existed. For example, consider the following simple example:

$ cd /tmp/example
$ git init
Initialized empty Git repository in /tmp/example/.git/
$ echo "Initial text" > README.md
$ git add README.md
$ git commit -m "initial commit"
[master (root-commit) 3f7522e] initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
$ echo "bad update" > README.md 
$ git commit -am "bad update"
[master a1b9870] bad update
 1 file changed, 1 insertion(+), 1 deletion(-)

In this example the commit history has two commits and the last one is a mistake. Using git revert:

$ git revert HEAD
[master 1db4eeb] Revert "bad update"
 1 file changed, 1 insertion(+), 1 deletion(-)

There will be 3 commits in the log:

$ git log --oneline
1db4eeb Revert "bad update"
a1b9870 bad update
3f7522e initial commit

So there is a consistent history of what has happened, yet the files are as if the bad update never occurred:

$ cat README.md 
Initial text

It doesn't matter where in the history the commit to be reverted is (in the above example, the last commit is reverted - any commit can be reverted).

Closing questions

do you have to do something else after?

A git revert is just another commit, so e.g. push to the remote so that other users can pull/fetch/merge the changes and you're done.

Do you have to commit the changes revert made or does revert directly commit to the repo?

git revert is a commit - there are no extra steps assuming reverting a single commit is what you wanted to do.

Obviously, you'll need to push again and probably announce your balls-up to the team.

Indeed - if the remote is in an unstable state - communicating to the rest of the team that they need to pull to get the fix (the reverting commit) would be the right thing to do :).

2 of 7
136

Use Git revert like so:

git revert <insert bad commit hash here>

git revert creates a new commit with the changes that are rolled back. git reset erases your Git history instead of making a new commit.

The steps after are the same as any other commit.

🌐
GitLab
docs.gitlab.com › topics › git › undo
Revert and undo changes | GitLab Docs
When you commit to your local repository with git commit, Git records your changes. Because you did not push to a remote repository yet, your changes are not public or shared with others. At this point, you can undo your changes. You can revert a commit while retaining the commit history.
Discussions

I'm struggling to understand how to roll back to a previous point. I want to disregard the crossed out chain completely. What am I missing here?
Edit: That was definitely it. I undid the new commit and created a new branch and it is acting as I was expecting now. I decided the last 3 commits I did were just not going to work, so I wanted to roll back to my v0.1.5a commit. So I "Undo Last Commit" a few times to get back there, then tried committing to a chain. I didn't actually create a branch, maybe that was what I did wrong? More on reddit.com
🌐 r/git
12
0
December 11, 2024
Revert commit on Website
Hello there! I'm beginner on GitHub, and can't resolve one problem - on desktop version i can "Revert changes in commit" in history without problems. But i can't find any way to revert commits on Website. I need to use the website and not the git console. A search on the web yielded no results ... More on github.com
🌐 github.com
8
18
🌐
Git
git-scm.com › docs › git-revert.html
Git - git-revert Documentation
This requires your working tree to be clean (no modifications from the HEAD commit). Note: git revert is used to record some new commits to reverse the effect of some earlier commits (often only a faulty one). If you want to throw away all uncommitted changes in your working directory, you ...
🌐
TheServerSide
theserverside.com › tutorial › How-to-git-revert-a-commit-A-simple-undo-changes-example
How to revert a Git commit: A simple example | TheServerSide
The purpose of the git revert command is to remove all the changes a single commit made to your source code repository. For example, if a past commit added a file named index.html to the repo, a git revert on that commit will remove the index.html ...
🌐
Atlassian
atlassian.com › git › tutorials › undoing changes › git revert
How to Revert a Commit in Git? | Atlassian Git Tutorial
A revert operation will take the specified commit, inverse the changes from that commit, and create a new "revert commit". The ref pointers are then updated to point at the new revert commit making it the tip of the branch.
Find elsewhere
🌐
Reddit
reddit.com › r/learnprogramming › using git, what happens if i revert a commit that was made prior to several other commits? will it undo all the subsequent commits?
r/learnprogramming on Reddit: Using Git, what happens if I revert a commit that was made prior to several other commits? Will it undo all the subsequent commits?
February 18, 2022 -

Also, if I just revert my most recent commit, make changes, then decide I want to go back to before I did the revert, can I do that? I've been manually making a new branch every time I want to work on a previous version of my code because I've been afraid to lose my current work by doing a revert.

If it makes a difference, I'm working in Visual Studio, with their built-in support for GitHub, not the command line. When I want to go back to a previous version of my code, I go to branch history, right click, and click "new branch". I know that can't be the best way to do it, but I've had a hard time finding a good explanation of how reverts actually work in Git/GitHub and I don't want to accidentally lose my current work.

Top answer
1 of 1
29
Good news: once something is committed in Git, you're unlikely to lose it unless you really go out of your way! So I admire that you're taking the safe route because you're afraid of losing data, but as you get to understand Git better, hopefully you can trust it! In Git, a "revert" means to make a NEW commit that undoes a previous commit. The entire previous history is still there. Let's say I make three commits: A: append "It was the best of times, it was the worst of times" B: append "it was the age of wisdom, it was the age of foolishness" C: append "it was the epoch of belief, it was the epoch of incredulity" At the end of this, my file looks like this: It was the best of times, it was the worst of times it was the age of wisdom, it was the age of foolishness it was the epoch of belief, it was the epoch of incredulity If I revert C, I'll end up with this history: A, B, C, revert-C My file will now look like this: It was the best of times, it was the worst of times it was the age of wisdom, it was the age of foolishness But that third line of text isn't gone. It's still there in my history. I can see it with "git diff" or "git show" or any number of other commands. Or I could check out a previous commit and create a new branch for it. You don't have to revert in order. Git reverts just one commit at a time. So if I revert A, my history will look like this: A, B, C, revert-A My file might look like this: it was the age of wisdom, it was the age of foolishness it was the epoch of belief, it was the epoch of incredulity However, trying to revert things out of order might fail. Git will be rightfully worried about a merge conflict and it might show you the diff and ask you to manually resolve it. If you wanted to undo all of those changes, you could: revert C revert B revert A Now you'd be right back where you started, but you'd still have all of your history. So...revert away! BTW, if you're curious, there is a totally different way to undo a few changes. If you instead ran: git reset --hard A, that would tell Git to reset back to when A was the only thing committed, and B and C had never been committed. That is erasing history! But, Git is nice and doesn't throw away B and C just yet. They can still be recovered if you made a mistake. So that's why you shouldn't worry!
🌐
YouTube
youtube.com › cameron mckenzie
How to Undo a Pushed Git Commit - Reset & Revert a Git Commit After Push - YouTube
Need to undo a pushed Git commit from GitHub, GitLab, Bitbucket or CodeCommit? Well, there are two ways to revert a pushed commit in git.You can revert a com...
Published   January 31, 2024
🌐
GitProtect.io
gitprotect.io › strona główna › how to undo a commit in git
How to Undo a Commit in Git - Blog | GitProtect.io
January 7, 2026 - I accidentally added this file to my current commit and I did a push. What’s next, any other subsequent commits? A quick git reset would require rewriting shared history (force-push), which is risky in a team setting. Git revert can remove the secret from the current code, but it will still remain in the repository history.
🌐
GitHub
github.com › orgs › community › discussions › 60023
Revert commit on Website · community · Discussion #60023
To revert a commit you can git reset --hard<commit-hash> then git push origin <branch-name>, where would likely be main for you as I assume you don't know much about branching yet.
🌐
CloudBees
cloudbees.com › blog › git-revert-explained
Git Revert Explained: Safely Undoing Your Changes
November 29, 2021 - It is an “undo” command, but technically it is much more than that. Git revert does not delete any commit in this project history. Instead, it inverts the changes implemented in a commit and appends new commits with the opposite effect.
🌐
Ben Holmes
bholmes.dev › blog › how-to-revert-your-git-commits-without-panicking
How to revert your git commits without panicking
Note that doing so will create a new commit meant to revert all changes made down to the commit specified. This works well since you should be able to push your changes and have a clean change log as intended. Worth warning that this will open a confirmation file in vi (assuming you're using the default git editor) for each commit being reverted.
🌐
Gitbybit
gitbybit.com › gitopedia › git-commands › git-revert
Gitopedia: git revert — create an undo commit
When you use git revert, Git creates a new commit that contains the inverse of the changes made in the original commit.
🌐
Graphite
graphite.com › guides › git-revert-commit-after-pushing
git revert commit after pushing
Once you have the commit hash, you can revert it using: ... This command creates a new commit that undoes the changes made by the commit specified by <commit-hash>. If the commit in question introduced changes across multiple files, Git might prompt you to confirm the revert process for each conflicted file.
🌐
OpenReplay
blog.openreplay.com › openreplay blog › undoing git commits after push: safely revert changes on remote repositories
Undoing Git Commits After Push: Safely Revert Changes on Remote Repositories
November 30, 2024 - Use git reset to undo local commits before pushing. Use git revert to safely undo pushed commits by creating a new commit that inverts the changes.
🌐
Aviator
aviator.co › home › blog › how to git undo commit: methods and best practices
How to Git Undo Commit: Methods and Best Practices - Aviator Blog
February 10, 2025 - Imagine you’re working on a platform for customer subscriptions and pushing a commit that accidentally removes the logic for automatic renewals. Other developers may have already pulled the changes, so you can’t use git reset. Instead, you use git revert to undo the changes safely.
🌐
DeployHQ
deployhq.com › learn git › reverting and undoing commits in git
How to Revert a Commit in Git: revert, reset, restore - DeployHQ
May 23, 2026 - A useful way to remember the ... rather than commits. git revert is the right tool when the commit you want to undo has already been pushed, or when you're working on a branch other people pull from....