

This allows you to inspect the changes reverted and implement new ones if needed. This does not affect any other commits you may have made before or after that particular commit.Īs seen in the image above, the command reverted the specified commit, leaving the reverted changes in the staged index. When you revert a previous commit, the command only removes the changes associated with the commit hash/ID specified. Using this command alone won’t do anything unless you specify the commit hash or reference (45111a). Reverting occurs in the Git CLI you will need to use the git revert command, which looks like this. When reverting, this operation takes the specific commit, inverts the changes from that commit, and implements a new reverse commit-only removing the changes tied to the reverted commit. Git revert undoes changes in a project commit history without tampering with it. This process will revert only the commit with the bug and create a safe way to proceed. In a situation like this, instead of manually trying to locate the bug-which, of course, will take more time-you can undo just the commit that introduced the bug by using git revert. After examining, you learn the bug was introduced to the project in the first commit you made that day. Suddenly, a few moments before making the fifth commit, you realize there’s a bug in the project. This makes it a handy command, especially when collaborating on a project.įor instance, let’s say you’re working on a project and have made four commits so far today. This process helps Git remove the unwanted commit from the codebase and retain the history of every commit and the reverted one. Instead, it inverts the changes implemented in a commit and appends new commits with the opposite effect. Git revert does not delete any commit in this project history. It is an “undo” command, but technically it is much more than that. You use git revert to record some new commits to reverse the effect of some earlier commits (possibly faulty ones). We will also look at other command line options and how this relates to resetting, amending, or reverting multiple commits.
#Sourcetree revert to previous commit code
This article will look at what revert means in the context of Git's workflow and the different usage scenarios, using code samples liberally.
#Sourcetree revert to previous commit free
Think of git revert as a “get out of jail free card” whenever you make a mistake while collaborating on a project. Git revert is a source code control command typically known as a way to “undo” commits in Git, but it goes beyond that. In fact, some of the frequently asked questions by Git and GitHub users include “How do I undo a commit I made in Git?” and “How do I revert the commit pushed to GitHub?” That’s why it’s crucial to understand some source code commands such as git revert. As a collaborator to a project, chances are that you will make a bad commit every once in a while-this is inevitable. A version control system such as Git can ease a developer’s life, providing an opportunity to manage and track a project's source code.
